home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2014 January / PCgo_CD_14_01.iso / nw.pak / Unnamed File 000656.unknown < prev    next >
Encoding:
Text File  |  2012-12-14  |  167.6 KB  |  5,619 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. WebInspector.JavaScriptBreakpointsSidebarPane = function(breakpointManager, showSourceLineDelegate)
  8. {
  9. WebInspector.SidebarPane.call(this, WebInspector.UIString("Breakpoints"));
  10.  
  11. this._breakpointManager = breakpointManager;
  12. this._showSourceLineDelegate = showSourceLineDelegate;
  13.  
  14. this.listElement = document.createElement("ol");
  15. this.listElement.className = "breakpoint-list";
  16.  
  17. this.emptyElement = document.createElement("div");
  18. this.emptyElement.className = "info";
  19. this.emptyElement.textContent = WebInspector.UIString("No Breakpoints");
  20.  
  21. this.bodyElement.appendChild(this.emptyElement);
  22.  
  23. this._items = new Map();
  24.  
  25. var breakpointLocations = this._breakpointManager.allBreakpointLocations();
  26. for (var i = 0; i < breakpointLocations.length; ++i)
  27. this._addBreakpoint(breakpointLocations[i].breakpoint, breakpointLocations[i].uiLocation);
  28.  
  29. this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointAdded, this._breakpointAdded, this);
  30. this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointRemoved, this._breakpointRemoved, this);
  31.  
  32. this.emptyElement.addEventListener("contextmenu", this._emptyElementContextMenu.bind(this), true);
  33. }
  34.  
  35. WebInspector.JavaScriptBreakpointsSidebarPane.prototype = {
  36. _emptyElementContextMenu: function(event)
  37. {
  38. var contextMenu = new WebInspector.ContextMenu(event);
  39. var breakpointActive = WebInspector.debuggerModel.breakpointsActive();
  40. var breakpointActiveTitle = WebInspector.UIString(breakpointActive ? "Deactivate Breakpoints" : "Activate Breakpoints");
  41. contextMenu.appendItem(breakpointActiveTitle, WebInspector.debuggerModel.setBreakpointsActive.bind(WebInspector.debuggerModel, !breakpointActive));
  42. contextMenu.show();
  43. },
  44.  
  45.  
  46. _breakpointAdded: function(event)
  47. {
  48. this._breakpointRemoved(event);
  49.  
  50. var breakpoint =   (event.data.breakpoint);
  51. var uiLocation =   (event.data.uiLocation);
  52. this._addBreakpoint(breakpoint, uiLocation);
  53. },
  54.  
  55.  
  56. _addBreakpoint: function(breakpoint, uiLocation)
  57. {
  58. var element = document.createElement("li");
  59. element.addStyleClass("cursor-pointer");
  60. element.addEventListener("contextmenu", this._breakpointContextMenu.bind(this, breakpoint), true);
  61. element.addEventListener("click", this._breakpointClicked.bind(this, uiLocation), false);
  62.  
  63. var checkbox = document.createElement("input");
  64. checkbox.className = "checkbox-elem";
  65. checkbox.type = "checkbox";
  66. checkbox.checked = breakpoint.enabled();
  67. checkbox.addEventListener("click", this._breakpointCheckboxClicked.bind(this, breakpoint), false);
  68. element.appendChild(checkbox);
  69.  
  70. var labelElement = document.createTextNode(WebInspector.formatLinkText(uiLocation.uiSourceCode.url, uiLocation.lineNumber));
  71. element.appendChild(labelElement);
  72.  
  73. var snippetElement = document.createElement("div");
  74. snippetElement.className = "source-text monospace";
  75. element.appendChild(snippetElement);
  76.  
  77.  
  78. function didRequestContent(content, contentEncoded, mimeType)
  79. {
  80. var lineEndings = content.lineEndings();
  81. if (uiLocation.lineNumber < lineEndings.length)
  82. snippetElement.textContent = content.substring(lineEndings[uiLocation.lineNumber - 1], lineEndings[uiLocation.lineNumber]);
  83. }
  84. uiLocation.uiSourceCode.requestContent(didRequestContent.bind(this));
  85.  
  86. element._data = uiLocation;
  87. var currentElement = this.listElement.firstChild;
  88. while (currentElement) {
  89. if (currentElement._data && this._compareBreakpoints(currentElement._data, element._data) > 0)
  90. break;
  91. currentElement = currentElement.nextSibling;
  92. }
  93. this._addListElement(element, currentElement);
  94.  
  95. var breakpointItem = {};
  96. breakpointItem.element = element;
  97. breakpointItem.checkbox = checkbox;
  98. this._items.put(breakpoint, breakpointItem);
  99.  
  100. if (!this.expanded)
  101. this.expanded = true;
  102. },
  103.  
  104.  
  105. _breakpointRemoved: function(event)
  106. {
  107. var breakpoint =   (event.data.breakpoint);
  108. var uiLocation =   (event.data.uiLocation);
  109. var breakpointItem = this._items.get(breakpoint);
  110. if (!breakpointItem)
  111. return;
  112. this._items.remove(breakpoint);
  113. this._removeListElement(breakpointItem.element);
  114. },
  115.  
  116.  
  117. highlightBreakpoint: function(breakpoint)
  118. {
  119. var breakpointItem = this._items.get(breakpoint);
  120. if (!breakpointItem)
  121. return;
  122. breakpointItem.element.addStyleClass("breakpoint-hit");
  123. this._highlightedBreakpointItem = breakpointItem;
  124. },
  125.  
  126. clearBreakpointHighlight: function()
  127. {
  128. if (this._highlightedBreakpointItem) {
  129. this._highlightedBreakpointItem.element.removeStyleClass("breakpoint-hit");
  130. delete this._highlightedBreakpointItem;
  131. }
  132. },
  133.  
  134. _breakpointClicked: function(uiLocation, event)
  135. {
  136. this._showSourceLineDelegate(uiLocation.uiSourceCode, uiLocation.lineNumber);
  137. },
  138.  
  139.  
  140. _breakpointCheckboxClicked: function(breakpoint, event)
  141. {
  142.  
  143. event.consume();
  144. breakpoint.setEnabled(event.target.checked);
  145. },
  146.  
  147.  
  148. _breakpointContextMenu: function(breakpoint, event)
  149. {
  150. var breakpoints = this._items.values();
  151. var contextMenu = new WebInspector.ContextMenu(event);
  152. contextMenu.appendItem(WebInspector.UIString("Remove Breakpoint"), breakpoint.remove.bind(breakpoint));
  153. if (breakpoints.length > 1) {
  154. var removeAllTitle = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove all breakpoints" : "Remove All Breakpoints");
  155. contextMenu.appendItem(removeAllTitle, this._breakpointManager.removeAllBreakpoints.bind(this._breakpointManager));
  156. }
  157.  
  158. contextMenu.appendSeparator();
  159. var breakpointActive = WebInspector.debuggerModel.breakpointsActive();
  160. var breakpointActiveTitle = WebInspector.UIString(breakpointActive ? "Deactivate Breakpoints" : "Activate Breakpoints");
  161. contextMenu.appendItem(breakpointActiveTitle, WebInspector.debuggerModel.setBreakpointsActive.bind(WebInspector.debuggerModel, !breakpointActive));
  162.  
  163. function enabledBreakpointCount(breakpoints)
  164. {
  165. var count = 0;
  166. for (var i = 0; i < breakpoints.length; ++i) {
  167. if (breakpoints[i].checkbox.checked)
  168. count++;
  169. }
  170. return count;
  171. }
  172. if (breakpoints.length > 1) {
  173. var enableBreakpointCount = enabledBreakpointCount(breakpoints);
  174. var enableTitle = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Enable all breakpoints" : "Enable All Breakpoints");
  175. var disableTitle = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Disable all breakpoints" : "Disable All Breakpoints");
  176.  
  177. contextMenu.appendSeparator();
  178.  
  179. contextMenu.appendItem(enableTitle, this._breakpointManager.toggleAllBreakpoints.bind(this._breakpointManager, true), !(enableBreakpointCount != breakpoints.length));
  180. contextMenu.appendItem(disableTitle, this._breakpointManager.toggleAllBreakpoints.bind(this._breakpointManager, false), !(enableBreakpointCount > 1));
  181. }
  182.  
  183. contextMenu.show();
  184. },
  185.  
  186. _addListElement: function(element, beforeElement)
  187. {
  188. if (beforeElement)
  189. this.listElement.insertBefore(element, beforeElement);
  190. else {
  191. if (!this.listElement.firstChild) {
  192. this.bodyElement.removeChild(this.emptyElement);
  193. this.bodyElement.appendChild(this.listElement);
  194. }
  195. this.listElement.appendChild(element);
  196. }
  197. },
  198.  
  199. _removeListElement: function(element)
  200. {
  201. this.listElement.removeChild(element);
  202. if (!this.listElement.firstChild) {
  203. this.bodyElement.removeChild(this.listElement);
  204. this.bodyElement.appendChild(this.emptyElement);
  205. }
  206. },
  207.  
  208. _compare: function(x, y)
  209. {
  210. if (x !== y)
  211. return x < y ? -1 : 1;
  212. return 0;
  213. },
  214.  
  215. _compareBreakpoints: function(b1, b2)
  216. {
  217. return this._compare(b1.url, b2.url) || this._compare(b1.lineNumber, b2.lineNumber);
  218. },
  219.  
  220. reset: function()
  221. {
  222. this.listElement.removeChildren();
  223. if (this.listElement.parentElement) {
  224. this.bodyElement.removeChild(this.listElement);
  225. this.bodyElement.appendChild(this.emptyElement);
  226. }
  227. this._items.clear();
  228. },
  229.  
  230. __proto__: WebInspector.SidebarPane.prototype
  231. }
  232.  
  233.  
  234. WebInspector.XHRBreakpointsSidebarPane = function()
  235. {
  236. WebInspector.NativeBreakpointsSidebarPane.call(this, WebInspector.UIString("XHR Breakpoints"));
  237.  
  238. this._breakpointElements = {};
  239.  
  240. var addButton = document.createElement("button");
  241. addButton.className = "pane-title-button add";
  242. addButton.addEventListener("click", this._addButtonClicked.bind(this), false);
  243. addButton.title = WebInspector.UIString("Add XHR breakpoint");
  244. this.titleElement.appendChild(addButton);
  245.  
  246. this.emptyElement.addEventListener("contextmenu", this._emptyElementContextMenu.bind(this), true);
  247.  
  248. this._restoreBreakpoints();
  249. }
  250.  
  251. WebInspector.XHRBreakpointsSidebarPane.prototype = {
  252. _emptyElementContextMenu: function(event)
  253. {
  254. var contextMenu = new WebInspector.ContextMenu(event);
  255. contextMenu.appendItem(WebInspector.UIString("Add Breakpoint"), this._addButtonClicked.bind(this));
  256. contextMenu.show();
  257. },
  258.  
  259. _addButtonClicked: function(event)
  260. {
  261. if (event)
  262. event.consume();
  263.  
  264. this.expanded = true;
  265.  
  266. var inputElementContainer = document.createElement("p");
  267. inputElementContainer.className = "breakpoint-condition";
  268. var inputElement = document.createElement("span");
  269. inputElementContainer.textContent = WebInspector.UIString("Break when URL contains:");
  270. inputElement.className = "editing";
  271. inputElement.id = "breakpoint-condition-input";
  272. inputElementContainer.appendChild(inputElement);
  273. this._addListElement(inputElementContainer, this.listElement.firstChild);
  274.  
  275. function finishEditing(accept, e, text)
  276. {
  277. this._removeListElement(inputElementContainer);
  278. if (accept) {
  279. this._setBreakpoint(text, true);
  280. this._saveBreakpoints();
  281. }
  282. }
  283.  
  284. var config = new WebInspector.EditingConfig(finishEditing.bind(this, true), finishEditing.bind(this, false));
  285. WebInspector.startEditing(inputElement, config);
  286. },
  287.  
  288. _setBreakpoint: function(url, enabled)
  289. {
  290. if (url in this._breakpointElements)
  291. return;
  292.  
  293. var element = document.createElement("li");
  294. element._url = url;
  295. element.addEventListener("contextmenu", this._contextMenu.bind(this, url), true);
  296.  
  297. var checkboxElement = document.createElement("input");
  298. checkboxElement.className = "checkbox-elem";
  299. checkboxElement.type = "checkbox";
  300. checkboxElement.checked = enabled;
  301. checkboxElement.addEventListener("click", this._checkboxClicked.bind(this, url), false);
  302. element._checkboxElement = checkboxElement;
  303. element.appendChild(checkboxElement);
  304.  
  305. var labelElement = document.createElement("span");
  306. if (!url)
  307. labelElement.textContent = WebInspector.UIString("Any XHR");
  308. else
  309. labelElement.textContent = WebInspector.UIString("URL contains \"%s\"", url);
  310. labelElement.addStyleClass("cursor-auto");
  311. labelElement.addEventListener("dblclick", this._labelClicked.bind(this, url), false);
  312. element.appendChild(labelElement);
  313.  
  314. var currentElement = this.listElement.firstChild;
  315. while (currentElement) {
  316. if (currentElement._url && currentElement._url < element._url)
  317. break;
  318. currentElement = currentElement.nextSibling;
  319. }
  320. this._addListElement(element, currentElement);
  321. this._breakpointElements[url] = element;
  322. if (enabled)
  323. DOMDebuggerAgent.setXHRBreakpoint(url);
  324. },
  325.  
  326. _removeBreakpoint: function(url)
  327. {
  328. var element = this._breakpointElements[url];
  329. if (!element)
  330. return;
  331.  
  332. this._removeListElement(element);
  333. delete this._breakpointElements[url];
  334. if (element._checkboxElement.checked)
  335. DOMDebuggerAgent.removeXHRBreakpoint(url);
  336. },
  337.  
  338. _contextMenu: function(url, event)
  339. {
  340. var contextMenu = new WebInspector.ContextMenu(event);
  341. function removeBreakpoint()
  342. {
  343. this._removeBreakpoint(url);
  344. this._saveBreakpoints();
  345. }
  346. function removeAllBreakpoints()
  347. {
  348. for (var url in this._breakpointElements)
  349. this._removeBreakpoint(url);
  350. this._saveBreakpoints();
  351. }
  352. var removeAllTitle = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove all breakpoints" : "Remove All Breakpoints");
  353.  
  354. contextMenu.appendItem(WebInspector.UIString("Add Breakpoint"), this._addButtonClicked.bind(this));
  355. contextMenu.appendItem(WebInspector.UIString("Remove Breakpoint"), removeBreakpoint.bind(this));
  356. contextMenu.appendItem(removeAllTitle, removeAllBreakpoints.bind(this));
  357. contextMenu.show();
  358. },
  359.  
  360. _checkboxClicked: function(url, event)
  361. {
  362. if (event.target.checked)
  363. DOMDebuggerAgent.setXHRBreakpoint(url);
  364. else
  365. DOMDebuggerAgent.removeXHRBreakpoint(url);
  366. this._saveBreakpoints();
  367. },
  368.  
  369. _labelClicked: function(url)
  370. {
  371. var element = this._breakpointElements[url];
  372. var inputElement = document.createElement("span");
  373. inputElement.className = "breakpoint-condition editing";
  374. inputElement.textContent = url;
  375. this.listElement.insertBefore(inputElement, element);
  376. element.addStyleClass("hidden");
  377.  
  378. function finishEditing(accept, e, text)
  379. {
  380. this._removeListElement(inputElement);
  381. if (accept) {
  382. this._removeBreakpoint(url);
  383. this._setBreakpoint(text, element._checkboxElement.checked);
  384. this._saveBreakpoints();
  385. } else
  386. element.removeStyleClass("hidden");
  387. }
  388.  
  389. WebInspector.startEditing(inputElement, new WebInspector.EditingConfig(finishEditing.bind(this, true), finishEditing.bind(this, false)));
  390. },
  391.  
  392. highlightBreakpoint: function(url)
  393. {
  394. var element = this._breakpointElements[url];
  395. if (!element)
  396. return;
  397. this.expanded = true;
  398. element.addStyleClass("breakpoint-hit");
  399. this._highlightedElement = element;
  400. },
  401.  
  402. clearBreakpointHighlight: function()
  403. {
  404. if (this._highlightedElement) {
  405. this._highlightedElement.removeStyleClass("breakpoint-hit");
  406. delete this._highlightedElement;
  407. }
  408. },
  409.  
  410. _saveBreakpoints: function()
  411. {
  412. var breakpoints = [];
  413. for (var url in this._breakpointElements)
  414. breakpoints.push({ url: url, enabled: this._breakpointElements[url]._checkboxElement.checked });
  415. WebInspector.settings.xhrBreakpoints.set(breakpoints);
  416. },
  417.  
  418. _restoreBreakpoints: function()
  419. {
  420. var breakpoints = WebInspector.settings.xhrBreakpoints.get();
  421. for (var i = 0; i < breakpoints.length; ++i) {
  422. var breakpoint = breakpoints[i];
  423. if (breakpoint && typeof breakpoint.url === "string")
  424. this._setBreakpoint(breakpoint.url, breakpoint.enabled);
  425. }
  426. },
  427.  
  428. __proto__: WebInspector.NativeBreakpointsSidebarPane.prototype
  429. }
  430.  
  431.  
  432. WebInspector.EventListenerBreakpointsSidebarPane = function()
  433. {
  434. WebInspector.SidebarPane.call(this, WebInspector.UIString("Event Listener Breakpoints"));
  435.  
  436. this.categoriesElement = document.createElement("ol");
  437. this.categoriesElement.tabIndex = 0;
  438. this.categoriesElement.addStyleClass("properties-tree");
  439. this.categoriesElement.addStyleClass("event-listener-breakpoints");
  440. this.categoriesTreeOutline = new TreeOutline(this.categoriesElement);
  441. this.bodyElement.appendChild(this.categoriesElement);
  442.  
  443. this._breakpointItems = {};
  444.  
  445.  
  446.  
  447. this._createCategory(WebInspector.UIString("Animation"), false, ["requestAnimationFrame", "cancelAnimationFrame", "animationFrameFired"]);
  448. this._createCategory(WebInspector.UIString("Control"), true, ["resize", "scroll", "zoom", "focus", "blur", "select", "change", "submit", "reset"]);
  449. this._createCategory(WebInspector.UIString("Clipboard"), true, ["copy", "cut", "paste", "beforecopy", "beforecut", "beforepaste"]);
  450. this._createCategory(WebInspector.UIString("DOM Mutation"), true, ["DOMActivate", "DOMFocusIn", "DOMFocusOut", "DOMAttrModified", "DOMCharacterDataModified", "DOMNodeInserted", "DOMNodeInsertedIntoDocument", "DOMNodeRemoved", "DOMNodeRemovedFromDocument", "DOMSubtreeModified", "DOMContentLoaded"]);
  451. this._createCategory(WebInspector.UIString("Device"), true, ["deviceorientation", "devicemotion"]);
  452. this._createCategory(WebInspector.UIString("Keyboard"), true, ["keydown", "keyup", "keypress", "input"]);
  453. this._createCategory(WebInspector.UIString("Load"), true, ["load", "unload", "abort", "error"]);
  454. this._createCategory(WebInspector.UIString("Mouse"), true, ["click", "dblclick", "mousedown", "mouseup", "mouseover", "mousemove", "mouseout", "mousewheel"]);
  455. this._createCategory(WebInspector.UIString("Timer"), false, ["setTimer", "clearTimer", "timerFired"]);
  456. this._createCategory(WebInspector.UIString("Touch"), true, ["touchstart", "touchmove", "touchend", "touchcancel"]);
  457.  
  458. this._restoreBreakpoints();
  459. }
  460.  
  461. WebInspector.EventListenerBreakpointsSidebarPane.categotyListener = "listener:";
  462. WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation = "instrumentation:";
  463.  
  464. WebInspector.EventListenerBreakpointsSidebarPane.eventNameForUI = function(eventName)
  465. {
  466. if (!WebInspector.EventListenerBreakpointsSidebarPane._eventNamesForUI) {
  467. WebInspector.EventListenerBreakpointsSidebarPane._eventNamesForUI = {
  468. "instrumentation:setTimer": WebInspector.UIString("Set Timer"),
  469. "instrumentation:clearTimer": WebInspector.UIString("Clear Timer"),
  470. "instrumentation:timerFired": WebInspector.UIString("Timer Fired"),
  471. "instrumentation:requestAnimationFrame": WebInspector.UIString("Request Animation Frame"),
  472. "instrumentation:cancelAnimationFrame": WebInspector.UIString("Cancel Animation Frame"),
  473. "instrumentation:animationFrameFired": WebInspector.UIString("Animation Frame Fired")
  474. };
  475. }
  476. return WebInspector.EventListenerBreakpointsSidebarPane._eventNamesForUI[eventName] || eventName.substring(eventName.indexOf(":") + 1);
  477. }
  478.  
  479. WebInspector.EventListenerBreakpointsSidebarPane.prototype = {
  480. _createCategory: function(name, isDOMEvent, eventNames)
  481. {
  482. var categoryItem = {};
  483. categoryItem.element = new TreeElement(name);
  484. this.categoriesTreeOutline.appendChild(categoryItem.element);
  485. categoryItem.element.listItemElement.addStyleClass("event-category");
  486. categoryItem.element.selectable = true;
  487.  
  488. categoryItem.checkbox = this._createCheckbox(categoryItem.element);
  489. categoryItem.checkbox.addEventListener("click", this._categoryCheckboxClicked.bind(this, categoryItem), true);
  490.  
  491. categoryItem.children = {};
  492. for (var i = 0; i < eventNames.length; ++i) {
  493. var eventName = (isDOMEvent ? WebInspector.EventListenerBreakpointsSidebarPane.categotyListener :  WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation) + eventNames[i];
  494.  
  495. var breakpointItem = {};
  496. var title = WebInspector.EventListenerBreakpointsSidebarPane.eventNameForUI(eventName);
  497. breakpointItem.element = new TreeElement(title);
  498. categoryItem.element.appendChild(breakpointItem.element);
  499. var hitMarker = document.createElement("div");
  500. hitMarker.className = "breakpoint-hit-marker";
  501. breakpointItem.element.listItemElement.appendChild(hitMarker);
  502. breakpointItem.element.listItemElement.addStyleClass("source-code");
  503. breakpointItem.element.selectable = true;
  504.  
  505. breakpointItem.checkbox = this._createCheckbox(breakpointItem.element);
  506. breakpointItem.checkbox.addEventListener("click", this._breakpointCheckboxClicked.bind(this, eventName), true);
  507. breakpointItem.parent = categoryItem;
  508.  
  509. this._breakpointItems[eventName] = breakpointItem;
  510. categoryItem.children[eventName] = breakpointItem;
  511. }
  512. },
  513.  
  514. _createCheckbox: function(treeElement)
  515. {
  516. var checkbox = document.createElement("input");
  517. checkbox.className = "checkbox-elem";
  518. checkbox.type = "checkbox";
  519. treeElement.listItemElement.insertBefore(checkbox, treeElement.listItemElement.firstChild);
  520. return checkbox;
  521. },
  522.  
  523. _categoryCheckboxClicked: function(categoryItem)
  524. {
  525. var checked = categoryItem.checkbox.checked;
  526. for (var eventName in categoryItem.children) {
  527. var breakpointItem = categoryItem.children[eventName];
  528. if (breakpointItem.checkbox.checked === checked)
  529. continue;
  530. if (checked)
  531. this._setBreakpoint(eventName);
  532. else
  533. this._removeBreakpoint(eventName);
  534. }
  535. this._saveBreakpoints();
  536. },
  537.  
  538. _breakpointCheckboxClicked: function(eventName, event)
  539. {
  540. if (event.target.checked)
  541. this._setBreakpoint(eventName);
  542. else
  543. this._removeBreakpoint(eventName);
  544. this._saveBreakpoints();
  545. },
  546.  
  547. _setBreakpoint: function(eventName)
  548. {
  549. var breakpointItem = this._breakpointItems[eventName];
  550. if (!breakpointItem)
  551. return;
  552. breakpointItem.checkbox.checked = true;
  553. if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener))
  554. DOMDebuggerAgent.setEventListenerBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener.length));
  555. else if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation))
  556. DOMDebuggerAgent.setInstrumentationBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation.length));
  557. this._updateCategoryCheckbox(breakpointItem.parent);
  558. },
  559.  
  560. _removeBreakpoint: function(eventName)
  561. {
  562. var breakpointItem = this._breakpointItems[eventName];
  563. if (!breakpointItem)
  564. return;
  565. breakpointItem.checkbox.checked = false;
  566. if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener))
  567. DOMDebuggerAgent.removeEventListenerBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener.length));
  568. else if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation))
  569. DOMDebuggerAgent.removeInstrumentationBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation.length));
  570. this._updateCategoryCheckbox(breakpointItem.parent);
  571. },
  572.  
  573. _updateCategoryCheckbox: function(categoryItem)
  574. {
  575. var hasEnabled = false, hasDisabled = false;
  576. for (var eventName in categoryItem.children) {
  577. var breakpointItem = categoryItem.children[eventName];
  578. if (breakpointItem.checkbox.checked)
  579. hasEnabled = true;
  580. else
  581. hasDisabled = true;
  582. }
  583. categoryItem.checkbox.checked = hasEnabled;
  584. categoryItem.checkbox.indeterminate = hasEnabled && hasDisabled;
  585. },
  586.  
  587. highlightBreakpoint: function(eventName)
  588. {
  589. var breakpointItem = this._breakpointItems[eventName];
  590. if (!breakpointItem)
  591. return;
  592. this.expanded = true;
  593. breakpointItem.parent.element.expand();
  594. breakpointItem.element.listItemElement.addStyleClass("breakpoint-hit");
  595. this._highlightedElement = breakpointItem.element.listItemElement;
  596. },
  597.  
  598. clearBreakpointHighlight: function()
  599. {
  600. if (this._highlightedElement) {
  601. this._highlightedElement.removeStyleClass("breakpoint-hit");
  602. delete this._highlightedElement;
  603. }
  604. },
  605.  
  606. _saveBreakpoints: function()
  607. {
  608. var breakpoints = [];
  609. for (var eventName in this._breakpointItems) {
  610. if (this._breakpointItems[eventName].checkbox.checked)
  611. breakpoints.push({ eventName: eventName });
  612. }
  613. WebInspector.settings.eventListenerBreakpoints.set(breakpoints);
  614. },
  615.  
  616. _restoreBreakpoints: function()
  617. {
  618. var breakpoints = WebInspector.settings.eventListenerBreakpoints.get();
  619. for (var i = 0; i < breakpoints.length; ++i) {
  620. var breakpoint = breakpoints[i];
  621. if (breakpoint && typeof breakpoint.eventName === "string")
  622. this._setBreakpoint(breakpoint.eventName);
  623. }
  624. },
  625.  
  626. __proto__: WebInspector.SidebarPane.prototype
  627. }
  628. ;
  629.  
  630.  
  631.  
  632. WebInspector.CallStackSidebarPane = function()
  633. {
  634. WebInspector.SidebarPane.call(this, WebInspector.UIString("Call Stack"));
  635. this._model = WebInspector.debuggerModel;
  636.  
  637. this.bodyElement.addEventListener("keydown", this._keyDown.bind(this), true);
  638. this.bodyElement.tabIndex = 0;
  639. }
  640.  
  641. WebInspector.CallStackSidebarPane.prototype = {
  642. update: function(callFrames)
  643. {
  644. this.bodyElement.removeChildren();
  645. this.placards = [];
  646.  
  647. if (!callFrames) {
  648. var infoElement = document.createElement("div");
  649. infoElement.className = "info";
  650. infoElement.textContent = WebInspector.UIString("Not Paused");
  651. this.bodyElement.appendChild(infoElement);
  652. return;
  653. }
  654.  
  655. for (var i = 0; i < callFrames.length; ++i) {
  656. var callFrame = callFrames[i];
  657. var placard = new WebInspector.CallStackSidebarPane.Placard(callFrame, this);
  658. placard.element.addEventListener("click", this._placardSelected.bind(this, placard), false);
  659. this.placards.push(placard);
  660. this.bodyElement.appendChild(placard.element);
  661. }
  662. },
  663.  
  664. setSelectedCallFrame: function(x)
  665. {
  666. for (var i = 0; i < this.placards.length; ++i) {
  667. var placard = this.placards[i];
  668. placard.selected = (placard._callFrame === x);
  669. }
  670. },
  671.  
  672. _selectNextCallFrameOnStack: function()
  673. {
  674. var index = this._selectedCallFrameIndex();
  675. if (index == -1)
  676. return;
  677. this._selectedPlacardByIndex(index + 1);
  678. },
  679.  
  680. _selectPreviousCallFrameOnStack: function()
  681. {
  682. var index = this._selectedCallFrameIndex();
  683. if (index == -1)
  684. return;
  685. this._selectedPlacardByIndex(index - 1);
  686. },
  687.  
  688. _selectedPlacardByIndex: function(index)
  689. {
  690. if (index < 0 || index >= this.placards.length)
  691. return;
  692. this._placardSelected(this.placards[index])
  693. },
  694.  
  695. _selectedCallFrameIndex: function()
  696. {
  697. if (!this._model.selectedCallFrame())
  698. return -1;
  699. for (var i = 0; i < this.placards.length; ++i) {
  700. var placard = this.placards[i];
  701. if (placard._callFrame === this._model.selectedCallFrame())
  702. return i;
  703. }
  704. return -1;
  705. },
  706.  
  707. _placardSelected: function(placard)
  708. {
  709. this._model.setSelectedCallFrame(placard._callFrame);
  710. },
  711.  
  712. _copyStackTrace: function()
  713. {
  714. var text = "";
  715. for (var i = 0; i < this.placards.length; ++i)
  716. text += this.placards[i].title + " (" + this.placards[i].subtitle + ")\n";
  717. InspectorFrontendHost.copyText(text);
  718. },
  719.  
  720. registerShortcuts: function(section, registerShortcutDelegate)
  721. {
  722. var nextCallFrame = WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Period,
  723. WebInspector.KeyboardShortcut.Modifiers.Ctrl);
  724. registerShortcutDelegate(nextCallFrame.key, this._selectNextCallFrameOnStack.bind(this));
  725.  
  726. var prevCallFrame = WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Comma,
  727. WebInspector.KeyboardShortcut.Modifiers.Ctrl);
  728. registerShortcutDelegate(prevCallFrame.key, this._selectPreviousCallFrameOnStack.bind(this));
  729.  
  730. section.addRelatedKeys([ nextCallFrame.name, prevCallFrame.name ], WebInspector.UIString("Next/previous call frame"));
  731. },
  732.  
  733. setStatus: function(status)
  734. {
  735. if (!this._statusMessageElement) {
  736. this._statusMessageElement = document.createElement("div");
  737. this._statusMessageElement.className = "info";
  738. this.bodyElement.appendChild(this._statusMessageElement);
  739. }
  740. if (typeof status === "string")
  741. this._statusMessageElement.textContent = status;
  742. else {
  743. this._statusMessageElement.removeChildren();
  744. this._statusMessageElement.appendChild(status);
  745. }
  746. },
  747.  
  748. _keyDown: function(event)
  749. {
  750. if (event.altKey || event.shiftKey || event.metaKey || event.ctrlKey)
  751. return;
  752.  
  753. if (event.keyIdentifier === "Up") {
  754. this._selectPreviousCallFrameOnStack();
  755. event.consume();
  756. } else if (event.keyIdentifier === "Down") {
  757. this._selectNextCallFrameOnStack();
  758. event.consume();
  759. }
  760. },
  761.  
  762. __proto__: WebInspector.SidebarPane.prototype
  763. }
  764.  
  765.  
  766. WebInspector.CallStackSidebarPane.Placard = function(callFrame, pane)
  767. {
  768. WebInspector.Placard.call(this, callFrame.functionName || WebInspector.UIString("(anonymous function)"), "");
  769. callFrame.createLiveLocation(this._update.bind(this));
  770. this.element.addEventListener("contextmenu", this._placardContextMenu.bind(this), true);
  771. this._callFrame = callFrame;
  772. this._pane = pane;
  773. }
  774.  
  775. WebInspector.CallStackSidebarPane.Placard.prototype = {
  776. _update: function(uiLocation)
  777. {
  778. this.subtitle = WebInspector.formatLinkText(uiLocation.uiSourceCode.url, uiLocation.lineNumber).trimMiddle(100);
  779. },
  780.  
  781. _placardContextMenu: function(event)
  782. {
  783. var contextMenu = new WebInspector.ContextMenu(event);
  784.  
  785. if (WebInspector.debuggerModel.canSetScriptSource()) {
  786. contextMenu.appendItem(WebInspector.UIString("Restart Frame"), this._restartFrame.bind(this));
  787. contextMenu.appendSeparator();
  788. }
  789. contextMenu.appendItem(WebInspector.UIString("Copy Stack Trace"), this._pane._copyStackTrace.bind(this._pane));
  790.  
  791. contextMenu.show();
  792. },
  793.  
  794. _restartFrame: function()
  795. {
  796. this._callFrame.restart(undefined);
  797. },
  798.  
  799. __proto__: WebInspector.Placard.prototype
  800. }
  801. ;
  802.  
  803.  
  804.  
  805. WebInspector.FilteredItemSelectionDialog = function(delegate)
  806. {
  807. WebInspector.DialogDelegate.call(this);
  808.  
  809. var xhr = new XMLHttpRequest();
  810. xhr.open("GET", "filteredItemSelectionDialog.css", false);
  811. xhr.send(null);
  812.  
  813. this.element = document.createElement("div");
  814. this.element.className = "js-outline-dialog";
  815. this.element.addEventListener("keydown", this._onKeyDown.bind(this), false);
  816. this.element.addEventListener("mousemove", this._onMouseMove.bind(this), false);
  817. this.element.addEventListener("click", this._onClick.bind(this), false);
  818. var styleElement = this.element.createChild("style");
  819. styleElement.type = "text/css";
  820. styleElement.textContent = xhr.responseText;
  821.  
  822. this._itemElements = [];
  823. this._elementIndexes = new Map();
  824. this._elementHighlightChanges = new Map();
  825.  
  826. this._promptElement = this.element.createChild("input", "monospace");
  827. this._promptElement.type = "text";
  828. this._promptElement.setAttribute("spellcheck", "false");
  829.  
  830. this._progressElement = this.element.createChild("div", "progress");
  831.  
  832. this._itemElementsContainer = document.createElement("div");
  833. this._itemElementsContainer.className = "container monospace";
  834. this._itemElementsContainer.addEventListener("scroll", this._onScroll.bind(this), false);
  835. this.element.appendChild(this._itemElementsContainer);
  836.  
  837. this._delegate = delegate;
  838.  
  839. this._delegate.requestItems(this._itemsLoaded.bind(this));
  840. }
  841.  
  842. WebInspector.FilteredItemSelectionDialog.prototype = {
  843.  
  844. position: function(element, relativeToElement)
  845. {
  846. const minWidth = 500;
  847. const minHeight = 204;
  848. var width = Math.max(relativeToElement.offsetWidth * 2 / 3, minWidth);
  849. var height = Math.max(relativeToElement.offsetHeight * 2 / 3, minHeight);
  850.  
  851. this.element.style.width = width + "px";
  852. this.element.style.height = height + "px";
  853.  
  854. const shadowPadding = 20; 
  855. element.positionAt(
  856. relativeToElement.totalOffsetLeft() + Math.max((relativeToElement.offsetWidth - width - 2 * shadowPadding) / 2, shadowPadding),
  857. relativeToElement.totalOffsetTop() + Math.max((relativeToElement.offsetHeight - height - 2 * shadowPadding) / 2, shadowPadding));
  858. },
  859.  
  860. focus: function()
  861. {
  862. WebInspector.setCurrentFocusElement(this._promptElement);
  863. },
  864.  
  865. willHide: function()
  866. {
  867. if (this._isHiding)
  868. return;
  869. this._isHiding = true;
  870. if (this._filterTimer)
  871. clearTimeout(this._filterTimer);
  872. },
  873.  
  874. onEnter: function()
  875. {
  876. if (!this._selectedElement)
  877. return;
  878. this._delegate.selectItem(this._elementIndexes.get(this._selectedElement), this._promptElement.value.trim());
  879. },
  880.  
  881.  
  882. _itemsLoaded: function(index, chunkLength, chunkIndex, chunkCount)
  883. {
  884. for (var i = index; i < index + chunkLength; ++i)
  885. this._itemElementsContainer.appendChild(this._createItemElement(i));
  886. this._filterItems();
  887.  
  888. if (chunkIndex === chunkCount)
  889. this._progressElement.style.backgroundImage = "";
  890. else {
  891. const color = "rgb(66, 129, 235)";
  892. const percent = ((chunkIndex / chunkCount) * 100) + "%";
  893. this._progressElement.style.backgroundImage = "-webkit-linear-gradient(left, " + color + ", " + color + " " + percent + ",  transparent " + percent + ")";
  894. }
  895. },
  896.  
  897.  
  898. _createItemElement: function(index)
  899. {
  900. if (this._itemElements[index])
  901. return this._itemElements[index];
  902.  
  903. var itemElement = document.createElement("div");
  904. itemElement.className = "item";
  905. itemElement._titleElement = itemElement.createChild("span");
  906. itemElement._titleElement.textContent = this._delegate.itemTitleAt(index);
  907. itemElement._titleSuffixElement = itemElement.createChild("span");
  908. itemElement._subtitleElement = itemElement.createChild("span", "subtitle");
  909. itemElement._subtitleElement.textContent = this._delegate.itemSubtitleAt(index);
  910. this._elementIndexes.put(itemElement, index);
  911. this._itemElements.push(itemElement);
  912. return itemElement;
  913. },
  914.  
  915.  
  916. _hideItemElement: function(itemElement)
  917. {
  918. itemElement.style.display = "none";
  919. },
  920.  
  921.  
  922. _itemElementVisible: function(itemElement)
  923. {
  924. return itemElement.style.display !== "none";
  925. },
  926.  
  927.  
  928. _showItemElement: function(itemElement)
  929. {
  930. itemElement.style.display = "";
  931. },
  932.  
  933.  
  934. _createSearchRegExp: function(query, isGlobal)
  935. {
  936. return this._innerCreateSearchRegExp(this._delegate.rewriteQuery(query), isGlobal);
  937. },
  938.  
  939.  
  940. _innerCreateSearchRegExp: function(query, isGlobal)
  941. {
  942. if (!query)
  943. return new RegExp(".*");
  944. query = query.trim();
  945.  
  946. var ignoreCase = (query === query.toLowerCase());
  947. var regExpString = query.escapeForRegExp().replace(/\\\*/g, ".*").replace(/\\\?/g, ".")
  948. if (ignoreCase)
  949. regExpString = regExpString.replace(/(?!^)(\\\.|[_:-])/g, "[^._:-]*$1");
  950. else
  951. regExpString = regExpString.replace(/(?!^)(\\\.|[A-Z_:-])/g, "[^.A-Z_:-]*$1");
  952. regExpString = regExpString;
  953. return new RegExp(regExpString, (ignoreCase ? "i" : "") + (isGlobal ? "g" : ""));
  954. },
  955.  
  956. _filterItems: function()
  957. {
  958. delete this._filterTimer;
  959.  
  960. var query = this._promptElement.value;
  961. query = query.trim();
  962. var regex = this._createSearchRegExp(query);
  963.  
  964. var firstElement;
  965. for (var i = 0; i < this._itemElements.length; ++i) {
  966. var itemElement = this._itemElements[i];
  967. itemElement._titleSuffixElement.textContent = this._delegate.itemSuffixAt(i);
  968. if (regex.test(this._delegate.itemKeyAt(i))) {
  969. this._showItemElement(itemElement);
  970. if (!firstElement)
  971. firstElement = itemElement;
  972. } else
  973. this._hideItemElement(itemElement);
  974. }
  975.  
  976. if (!this._selectedElement || !this._itemElementVisible(this._selectedElement))
  977. this._updateSelection(firstElement);
  978.  
  979. if (query) {
  980. this._highlightItems(query);
  981. this._query = query;
  982. } else {
  983. this._clearHighlight();
  984. delete this._query;
  985. }
  986. },
  987.  
  988. _onKeyDown: function(event)
  989. {
  990. function nextItem(itemElement, isPageScroll, forward)
  991. {
  992. var scrollItemsLeft = isPageScroll && this._rowsPerViewport ? this._rowsPerViewport : 1;
  993. var candidate = itemElement;
  994. var lastVisibleCandidate = candidate;
  995. do {
  996. candidate = forward ? candidate.nextSibling : candidate.previousSibling;
  997. if (!candidate) {
  998. if (isPageScroll)
  999. return lastVisibleCandidate;
  1000. else
  1001. candidate = forward ? this._itemElementsContainer.firstChild : this._itemElementsContainer.lastChild;
  1002. }
  1003. if (!this._itemElementVisible(candidate))
  1004. continue;
  1005. lastVisibleCandidate = candidate;
  1006. --scrollItemsLeft;
  1007. } while (scrollItemsLeft && candidate !== this._selectedElement);
  1008.  
  1009. return candidate;
  1010. }
  1011.  
  1012. if (this._selectedElement) {
  1013. var candidate;
  1014. switch (event.keyCode) {
  1015. case WebInspector.KeyboardShortcut.Keys.Down.code:
  1016. candidate = nextItem.call(this, this._selectedElement, false, true);
  1017. break;
  1018. case WebInspector.KeyboardShortcut.Keys.Up.code:
  1019. candidate = nextItem.call(this, this._selectedElement, false, false);
  1020. break;
  1021. case WebInspector.KeyboardShortcut.Keys.PageDown.code:
  1022. candidate = nextItem.call(this, this._selectedElement, true, true);
  1023. break;
  1024. case WebInspector.KeyboardShortcut.Keys.PageUp.code:
  1025. candidate = nextItem.call(this, this._selectedElement, true, false);
  1026. break;
  1027. }
  1028.  
  1029. if (candidate) {
  1030. this._updateSelection(candidate);
  1031. event.preventDefault();
  1032. return;
  1033. }
  1034. }
  1035.  
  1036. if (event.keyIdentifier !== "Shift" && event.keyIdentifier !== "Ctrl" && event.keyIdentifier !== "Meta" && event.keyIdentifier !== "Left" && event.keyIdentifier !== "Right")
  1037. this._scheduleFilter();
  1038. },
  1039.  
  1040. _scheduleFilter: function()
  1041. {
  1042. if (this._filterTimer)
  1043. return;
  1044. this._filterTimer = setTimeout(this._filterItems.bind(this), 0);
  1045. },
  1046.  
  1047.  
  1048. _updateSelection: function(newSelectedElement)
  1049. {
  1050. if (this._selectedElement === newSelectedElement)
  1051. return;
  1052. if (this._selectedElement)
  1053. this._selectedElement.removeStyleClass("selected");
  1054.  
  1055. this._selectedElement = newSelectedElement;
  1056. if (newSelectedElement) {
  1057. newSelectedElement.addStyleClass("selected");
  1058. newSelectedElement.scrollIntoViewIfNeeded(false);
  1059. if (!this._itemHeight) {
  1060. this._itemHeight = newSelectedElement.offsetHeight;
  1061. this._rowsPerViewport = Math.floor(this._itemElementsContainer.offsetHeight / this._itemHeight);
  1062. }
  1063. }
  1064. },
  1065.  
  1066. _onClick: function(event)
  1067. {
  1068. var itemElement = event.target.enclosingNodeOrSelfWithClass("item");
  1069. if (!itemElement)
  1070. return;
  1071. this._updateSelection(itemElement);
  1072. this._delegate.selectItem(this._elementIndexes.get(this._selectedElement), this._promptElement.value.trim());
  1073. WebInspector.Dialog.hide();
  1074. },
  1075.  
  1076. _onMouseMove: function(event)
  1077. {
  1078. var itemElement = event.target.enclosingNodeOrSelfWithClass("item");
  1079. if (!itemElement)
  1080. return;
  1081. this._updateSelection(itemElement);
  1082. },
  1083.  
  1084. _onScroll: function()
  1085. {
  1086. if (this._query)
  1087. this._highlightItems(this._query);
  1088. else
  1089. this._clearHighlight();
  1090. },
  1091.  
  1092.  
  1093. _highlightItems: function(query)
  1094. {
  1095. var regex = this._createSearchRegExp(query, true);
  1096. for (var i = 0; i < this._delegate.itemsCount(); ++i) {
  1097. var itemElement = this._itemElements[i];
  1098. if (this._itemElementVisible(itemElement) && this._itemElementInViewport(itemElement))
  1099. this._highlightItem(itemElement, regex);
  1100. }
  1101. },
  1102.  
  1103. _clearHighlight: function()
  1104. {
  1105. for (var i = 0; i < this._delegate.itemsCount(); ++i)
  1106. this._clearElementHighlight(this._itemElements[i]);
  1107. },
  1108.  
  1109.  
  1110. _clearElementHighlight: function(itemElement)
  1111. {
  1112. var changes = this._elementHighlightChanges.get(itemElement)
  1113. if (changes) {
  1114. WebInspector.revertDomChanges(changes);
  1115. this._elementHighlightChanges.remove(itemElement);
  1116. }
  1117. },
  1118.  
  1119.  
  1120. _highlightItem: function(itemElement, regex)
  1121. {
  1122. this._clearElementHighlight(itemElement);
  1123.  
  1124. var key = this._delegate.itemKeyAt(this._elementIndexes.get(itemElement));
  1125. var ranges = [];
  1126.  
  1127. var match;
  1128. while ((match = regex.exec(key)) !== null && match[0]) {
  1129. ranges.push({ offset: match.index, length: regex.lastIndex - match.index });
  1130. }
  1131.  
  1132. var changes = [];
  1133. WebInspector.highlightRangesWithStyleClass(itemElement, ranges, "highlight", changes);
  1134.  
  1135. if (changes.length)
  1136. this._elementHighlightChanges.put(itemElement, changes);
  1137. },
  1138.  
  1139.  
  1140. _itemElementInViewport: function(itemElement)
  1141. {
  1142. if (itemElement.offsetTop + this._itemHeight < this._itemElementsContainer.scrollTop)
  1143. return false;
  1144. if (itemElement.offsetTop > this._itemElementsContainer.scrollTop + this._itemHeight * (this._rowsPerViewport + 1))
  1145. return false;
  1146. return true;
  1147. },
  1148.  
  1149. __proto__: WebInspector.DialogDelegate.prototype
  1150. }
  1151.  
  1152.  
  1153. WebInspector.SelectionDialogContentProvider = function()
  1154. {
  1155. }
  1156.  
  1157. WebInspector.SelectionDialogContentProvider.prototype = {
  1158.  
  1159. itemTitleAt: function(itemIndex) { },
  1160.  
  1161.  
  1162. itemSuffixAt: function(itemIndex) { },
  1163.  
  1164.  
  1165. itemSubtitleAt: function(itemIndex) { },
  1166.  
  1167.  
  1168. itemKeyAt: function(itemIndex) { },
  1169.  
  1170.  
  1171. itemsCount: function() { },
  1172.  
  1173.  
  1174. requestItems: function(callback) { },
  1175.  
  1176.  
  1177. selectItem: function(itemIndex, promptValue) { },
  1178.  
  1179.  
  1180. rewriteQuery: function(query) { },
  1181. }
  1182.  
  1183.  
  1184. WebInspector.JavaScriptOutlineDialog = function(view, contentProvider)
  1185. {
  1186. WebInspector.SelectionDialogContentProvider.call(this);
  1187.  
  1188. this._functionItems = [];
  1189. this._view = view;
  1190. this._contentProvider = contentProvider;
  1191. }
  1192.  
  1193.  
  1194. WebInspector.JavaScriptOutlineDialog.show = function(view, contentProvider)
  1195. {
  1196. if (WebInspector.Dialog.currentInstance())
  1197. return null;
  1198. var delegate = new WebInspector.JavaScriptOutlineDialog(view, contentProvider);
  1199. var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(delegate);
  1200. WebInspector.Dialog.show(view.element, filteredItemSelectionDialog);
  1201. }
  1202.  
  1203. WebInspector.JavaScriptOutlineDialog.prototype = {
  1204.  
  1205. itemTitleAt: function(itemIndex)
  1206. {
  1207. var functionItem = this._functionItems[itemIndex];
  1208. return functionItem.name + (functionItem.arguments ? functionItem.arguments : "");
  1209. },
  1210.  
  1211.  
  1212. itemSuffixAt: function(itemIndex)
  1213. {
  1214. return "";
  1215. },
  1216.  
  1217.  
  1218. itemSubtitleAt: function(itemIndex)
  1219. {
  1220. return ":" + (this._functionItems[itemIndex].line + 1);
  1221. },
  1222.  
  1223.  
  1224. itemKeyAt: function(itemIndex)
  1225. {
  1226. return this._functionItems[itemIndex].name;
  1227. },
  1228.  
  1229.  
  1230. itemsCount: function()
  1231. {
  1232. return this._functionItems.length;
  1233. },
  1234.  
  1235.  
  1236. requestItems: function(callback)
  1237. {
  1238.  
  1239. function contentCallback(content, contentEncoded, mimeType)
  1240. {
  1241. if (this._outlineWorker)
  1242. this._outlineWorker.terminate();
  1243. this._outlineWorker = new Worker("ScriptFormatterWorker.js");
  1244. this._outlineWorker.onmessage = this._didBuildOutlineChunk.bind(this, callback);
  1245. const method = "outline";
  1246. this._outlineWorker.postMessage({ method: method, params: { content: content } });
  1247. }
  1248. this._contentProvider.requestContent(contentCallback.bind(this));
  1249. },
  1250.  
  1251. _didBuildOutlineChunk: function(callback, event)
  1252. {
  1253. var data = event.data;
  1254.  
  1255. var index = this._functionItems.length;
  1256. var chunk = data["chunk"];
  1257. for (var i = 0; i < chunk.length; ++i)
  1258. this._functionItems.push(chunk[i]);
  1259. callback(index, chunk.length, data.index, data.total);
  1260.  
  1261. if (data.total === data.index && this._outlineWorker) {
  1262. this._outlineWorker.terminate();
  1263. delete this._outlineWorker;
  1264. }
  1265. },
  1266.  
  1267.  
  1268. selectItem: function(itemIndex, promptValue)
  1269. {
  1270. var lineNumber = this._functionItems[itemIndex].line;
  1271. if (!isNaN(lineNumber) && lineNumber >= 0)
  1272. this._view.highlightLine(lineNumber);
  1273. this._view.focus();
  1274. },
  1275.  
  1276.  
  1277. rewriteQuery: function(query)
  1278. {
  1279. return query;
  1280. },
  1281.  
  1282. __proto__: WebInspector.SelectionDialogContentProvider.prototype
  1283. }
  1284.  
  1285.  
  1286. WebInspector.OpenResourceDialog = function(panel, uiSourceCodeProvider)
  1287. {
  1288. WebInspector.SelectionDialogContentProvider.call(this);
  1289. this._panel = panel;
  1290.  
  1291. this._uiSourceCodes = uiSourceCodeProvider.uiSourceCodes();
  1292.  
  1293. function filterOutEmptyURLs(uiSourceCode)
  1294. {
  1295. return !!uiSourceCode.parsedURL.lastPathComponent;
  1296. }
  1297. this._uiSourceCodes = this._uiSourceCodes.filter(filterOutEmptyURLs);
  1298.  
  1299. function compareFunction(uiSourceCode1, uiSourceCode2)
  1300. {
  1301. return uiSourceCode1.parsedURL.lastPathComponent.localeCompare(uiSourceCode2.parsedURL.lastPathComponent);
  1302. }
  1303. this._uiSourceCodes.sort(compareFunction);
  1304. }
  1305.  
  1306. WebInspector.OpenResourceDialog.prototype = {
  1307.  
  1308. itemTitleAt: function(itemIndex)
  1309. {
  1310. return this._uiSourceCodes[itemIndex].parsedURL.lastPathComponent;
  1311. },
  1312.  
  1313.  
  1314. itemSuffixAt: function(itemIndex)
  1315. {
  1316. return this._queryLineNumber || "";
  1317. },
  1318.  
  1319.  
  1320. itemSubtitleAt: function(itemIndex)
  1321. {
  1322. return this._uiSourceCodes[itemIndex].parsedURL.folderPathComponents;
  1323. },
  1324.  
  1325.  
  1326. itemKeyAt: function(itemIndex)
  1327. {
  1328. return this._uiSourceCodes[itemIndex].parsedURL.lastPathComponent;
  1329. },
  1330.  
  1331.  
  1332. itemsCount: function()
  1333. {
  1334. return this._uiSourceCodes.length;
  1335. },
  1336.  
  1337.  
  1338. requestItems: function(callback)
  1339. {
  1340. callback(0, this._uiSourceCodes.length, 1, 1);
  1341. },
  1342.  
  1343.  
  1344. selectItem: function(itemIndex, promptValue)
  1345. {
  1346. var lineNumberMatch = promptValue.match(/[^:]+\:([\d]*)$/);
  1347. var lineNumber = lineNumberMatch ? Math.max(parseInt(lineNumberMatch[1], 10) - 1, 0) : 0;
  1348. this._panel.showUISourceCode(this._uiSourceCodes[itemIndex], lineNumber);
  1349. },
  1350.  
  1351.  
  1352. rewriteQuery: function(query)
  1353. {
  1354. if (!query)
  1355. return query;
  1356. query = query.trim();
  1357. var lineNumberMatch = query.match(/([^:]+)(\:[\d]*)$/);
  1358. this._queryLineNumber = lineNumberMatch ? lineNumberMatch[2] : "";
  1359. return lineNumberMatch ? lineNumberMatch[1] : query;
  1360. },
  1361.  
  1362. __proto__: WebInspector.SelectionDialogContentProvider.prototype
  1363. }
  1364.  
  1365.  
  1366. WebInspector.OpenResourceDialog.show = function(panel, uiSourceCodeProvider, relativeToElement)
  1367. {
  1368. if (WebInspector.Dialog.currentInstance())
  1369. return;
  1370.  
  1371. var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(new WebInspector.OpenResourceDialog(panel, uiSourceCodeProvider));
  1372. WebInspector.Dialog.show(relativeToElement, filteredItemSelectionDialog);
  1373. }
  1374. ;
  1375.  
  1376.  
  1377.  
  1378. WebInspector.JavaScriptSourceFrame = function(scriptsPanel, uiSourceCode)
  1379. {
  1380. this._scriptsPanel = scriptsPanel;
  1381. this._breakpointManager = WebInspector.breakpointManager;
  1382. this._uiSourceCode = uiSourceCode;
  1383.  
  1384. var locations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
  1385. for (var i = 0; i < locations.length; ++i)
  1386. this._breakpointAdded({data:locations[i]});
  1387.  
  1388. WebInspector.SourceFrame.call(this, uiSourceCode);
  1389.  
  1390. this._popoverHelper = new WebInspector.ObjectPopoverHelper(this.textEditor.element,
  1391. this._getPopoverAnchor.bind(this), this._resolveObjectForPopover.bind(this), this._onHidePopover.bind(this), true);
  1392.  
  1393. this.textEditor.element.addEventListener("keydown", this._onKeyDown.bind(this), true);
  1394.  
  1395. this.textEditor.addEventListener(WebInspector.TextEditor.Events.GutterClick, this._handleGutterClick.bind(this), this);
  1396.  
  1397. this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointAdded, this._breakpointAdded, this);
  1398. this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointRemoved, this._breakpointRemoved, this);
  1399.  
  1400. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._onFormattedChanged, this);
  1401. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
  1402. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessageAdded, this._consoleMessageAdded, this);
  1403. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessageRemoved, this._consoleMessageRemoved, this);
  1404. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessagesCleared, this._consoleMessagesCleared, this);
  1405. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.SourceMappingChanged, this._onSourceMappingChanged, this);
  1406.  
  1407. this._updateScriptFile();
  1408. }
  1409.  
  1410. WebInspector.JavaScriptSourceFrame.prototype = {
  1411.  
  1412. wasShown: function()
  1413. {
  1414. WebInspector.SourceFrame.prototype.wasShown.call(this);
  1415. },
  1416.  
  1417. willHide: function()
  1418. {
  1419. WebInspector.SourceFrame.prototype.willHide.call(this);
  1420. this._popoverHelper.hidePopover();
  1421. },
  1422.  
  1423.  
  1424. canEditSource: function()
  1425. {
  1426. return this._uiSourceCode.isEditable();
  1427. },
  1428.  
  1429.  
  1430. commitEditing: function(text)
  1431. {
  1432. if (!this._uiSourceCode.isDirty())
  1433. return;
  1434.  
  1435. this._isCommittingEditing = true;
  1436. this._uiSourceCode.commitWorkingCopy(function() { });
  1437. delete this._isCommittingEditing;
  1438. },
  1439.  
  1440.  
  1441. _onFormattedChanged: function(event)
  1442. {
  1443. var content =   (event.data.content);
  1444. this._textEditor.setReadOnly(this._uiSourceCode.formatted());
  1445. this._innerSetContent(content);
  1446. },
  1447.  
  1448.  
  1449. _onWorkingCopyChanged: function(event)
  1450. {
  1451. this._innerSetContent(this._uiSourceCode.workingCopy());
  1452. },
  1453.  
  1454. _innerSetContent: function(content)
  1455. {
  1456. if (this._isSettingWorkingCopy || this._isCommittingEditing)
  1457. return;
  1458.  
  1459. this.setContent(content, false, this._uiSourceCode.mimeType());
  1460. },
  1461.  
  1462. populateLineGutterContextMenu: function(contextMenu, lineNumber)
  1463. {
  1464. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Continue to here" : "Continue to Here"), this._continueToLine.bind(this, lineNumber));
  1465.  
  1466. var breakpoint = this._breakpointManager.findBreakpoint(this._uiSourceCode, lineNumber);
  1467. if (!breakpoint) {
  1468.  
  1469. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add breakpoint" : "Add Breakpoint"), this._setBreakpoint.bind(this, lineNumber, "", true));
  1470. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add conditional breakpoint…" : "Add Conditional Breakpoint…"), this._editBreakpointCondition.bind(this, lineNumber));
  1471. } else {
  1472.  
  1473. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove breakpoint" : "Remove Breakpoint"), breakpoint.remove.bind(breakpoint));
  1474. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Edit breakpoint…" : "Edit Breakpoint…"), this._editBreakpointCondition.bind(this, lineNumber, breakpoint));
  1475. if (breakpoint.enabled())
  1476. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Disable breakpoint" : "Disable Breakpoint"), breakpoint.setEnabled.bind(breakpoint, false));
  1477. else
  1478. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Enable breakpoint" : "Enable Breakpoint"), breakpoint.setEnabled.bind(breakpoint, true));
  1479. }
  1480. },
  1481.  
  1482. populateTextAreaContextMenu: function(contextMenu, lineNumber)
  1483. {
  1484. WebInspector.SourceFrame.prototype.populateTextAreaContextMenu.call(this, contextMenu, lineNumber);
  1485. var selection = window.getSelection();
  1486. if (selection.type === "Range" && !selection.isCollapsed) {
  1487. var addToWatchLabel = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add to watch" : "Add to Watch");
  1488. contextMenu.appendItem(addToWatchLabel, this._scriptsPanel.addToWatch.bind(this._scriptsPanel, selection.toString()));
  1489. var evaluateLabel = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Evaluate in console" : "Evaluate in Console");
  1490. contextMenu.appendItem(evaluateLabel, WebInspector.evaluateInConsole.bind(WebInspector, selection.toString()));
  1491. contextMenu.appendSeparator();
  1492. }
  1493. contextMenu.appendApplicableItems(this._uiSourceCode);
  1494. },
  1495.  
  1496. onTextChanged: function(oldRange, newRange)
  1497. {
  1498. WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, newRange);
  1499. this._isSettingWorkingCopy = true;
  1500. this._uiSourceCode.setWorkingCopy(this._textEditor.text());
  1501. delete this._isSettingWorkingCopy;
  1502. },
  1503.  
  1504. _willMergeToVM: function()
  1505. {
  1506. if (this._supportsEnabledBreakpointsWhileEditing())
  1507. return;
  1508. this._preserveDecorations = true;
  1509. },
  1510.  
  1511. _didMergeToVM: function()
  1512. {
  1513. if (this._supportsEnabledBreakpointsWhileEditing())
  1514. return;
  1515. delete this._preserveDecorations;
  1516. this._restoreBreakpointsAfterEditing();
  1517. },
  1518.  
  1519. _willDivergeFromVM: function()
  1520. {
  1521. if (this._supportsEnabledBreakpointsWhileEditing())
  1522. return;
  1523. this._preserveDecorations = true;
  1524. },
  1525.  
  1526. _didDivergeFromVM: function()
  1527. {
  1528. if (this._supportsEnabledBreakpointsWhileEditing())
  1529. return;
  1530. delete this._preserveDecorations;
  1531. this._muteBreakpointsWhileEditing();
  1532. },
  1533.  
  1534. _muteBreakpointsWhileEditing: function()
  1535. {
  1536. for (var lineNumber = 0; lineNumber < this._textEditor.linesCount; ++lineNumber) {
  1537. var breakpointDecoration = this._textEditor.getAttribute(lineNumber, "breakpoint");
  1538. if (!breakpointDecoration)
  1539. continue;
  1540. this._removeBreakpointDecoration(lineNumber);
  1541. this._addBreakpointDecoration(lineNumber, breakpointDecoration.condition, breakpointDecoration.enabled, true);
  1542. }
  1543. },
  1544.  
  1545. _supportsEnabledBreakpointsWhileEditing: function()
  1546. {
  1547. return this._uiSourceCode.isSnippet;
  1548. },
  1549.  
  1550. _restoreBreakpointsAfterEditing: function()
  1551. {
  1552. var breakpoints = {};
  1553.  
  1554. for (var lineNumber = 0; lineNumber < this._textEditor.linesCount; ++lineNumber) {
  1555. var breakpointDecoration = this._textEditor.getAttribute(lineNumber, "breakpoint");
  1556. if (breakpointDecoration) {
  1557. breakpoints[lineNumber] = breakpointDecoration;
  1558. this._removeBreakpointDecoration(lineNumber);
  1559. }
  1560. }
  1561.  
  1562.  
  1563. var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
  1564. var lineNumbers = {};
  1565. for (var i = 0; i < breakpointLocations.length; ++i) {
  1566. var breakpoint = breakpointLocations[i].breakpoint;
  1567. breakpointLocations[i].breakpoint.remove();
  1568. }
  1569.  
  1570.  
  1571. for (var lineNumberString in breakpoints) {
  1572. var lineNumber = parseInt(lineNumberString, 10);
  1573. if (isNaN(lineNumber))
  1574. continue;
  1575. var breakpointDecoration = breakpoints[lineNumberString];
  1576. this._setBreakpoint(lineNumber, breakpointDecoration.condition, breakpointDecoration.enabled);
  1577. }
  1578. },
  1579.  
  1580. _getPopoverAnchor: function(element, event)
  1581. {
  1582. if (!WebInspector.debuggerModel.isPaused())
  1583. return null;
  1584. if (window.getSelection().type === "Range")
  1585. return null;
  1586. var lineElement = element.enclosingNodeOrSelfWithClass("webkit-line-content");
  1587. if (!lineElement)
  1588. return null;
  1589.  
  1590. if (element.hasStyleClass("webkit-javascript-ident"))
  1591. return element;
  1592.  
  1593. if (element.hasStyleClass("source-frame-token"))
  1594. return element;
  1595.  
  1596.  
  1597. if (element.hasStyleClass("webkit-javascript-keyword"))
  1598. return element.textContent === "this" ? element : null;
  1599.  
  1600. if (element !== lineElement || lineElement.childElementCount)
  1601. return null;
  1602.  
  1603.  
  1604.  
  1605. var lineContent = lineElement.textContent;
  1606. var ranges = [];
  1607. var regex = new RegExp("[a-zA-Z_\$0-9]+", "g");
  1608. var match;
  1609. while (regex.lastIndex < lineContent.length && (match = regex.exec(lineContent)))
  1610. ranges.push({offset: match.index, length: regex.lastIndex - match.index});
  1611.  
  1612.  
  1613. var changes = [];
  1614. WebInspector.highlightRangesWithStyleClass(lineElement, ranges, "source-frame-token", changes);
  1615. var lineOffsetLeft = lineElement.totalOffsetLeft();
  1616. for (var child = lineElement.firstChild; child; child = child.nextSibling) {
  1617. if (child.nodeType !== Node.ELEMENT_NODE || !child.hasStyleClass("source-frame-token"))
  1618. continue;
  1619. if (event.x > lineOffsetLeft + child.offsetLeft && event.x < lineOffsetLeft + child.offsetLeft + child.offsetWidth) {
  1620. var text = child.textContent;
  1621. return (text === "this" || !WebInspector.SourceJavaScriptTokenizer.Keywords[text]) ? child : null;
  1622. }
  1623. }
  1624. return null;
  1625. },
  1626.  
  1627. _resolveObjectForPopover: function(element, showCallback, objectGroupName)
  1628. {
  1629. this._highlightElement = this._highlightExpression(element);
  1630.  
  1631.  
  1632. function showObjectPopover(result, wasThrown)
  1633. {
  1634. if (!WebInspector.debuggerModel.isPaused()) {
  1635. this._popoverHelper.hidePopover();
  1636. return;
  1637. }
  1638. showCallback(WebInspector.RemoteObject.fromPayload(result), wasThrown, this._highlightElement);
  1639.  
  1640. if (this._highlightElement)
  1641. this._highlightElement.addStyleClass("source-frame-eval-expression");
  1642. }
  1643.  
  1644. if (!WebInspector.debuggerModel.isPaused()) {
  1645. this._popoverHelper.hidePopover();
  1646. return;
  1647. }
  1648. var selectedCallFrame = WebInspector.debuggerModel.selectedCallFrame();
  1649. selectedCallFrame.evaluate(this._highlightElement.textContent, objectGroupName, false, true, false, false, showObjectPopover.bind(this));
  1650. },
  1651.  
  1652. _onHidePopover: function()
  1653. {
  1654.  
  1655. var highlightElement = this._highlightElement;
  1656. if (!highlightElement)
  1657. return;
  1658.  
  1659.  
  1660. var parentElement = highlightElement.parentElement;
  1661. if (parentElement) {
  1662. var child = highlightElement.firstChild;
  1663. while (child) {
  1664. var nextSibling = child.nextSibling;
  1665. parentElement.insertBefore(child, highlightElement);
  1666. child = nextSibling;
  1667. }
  1668. parentElement.removeChild(highlightElement);
  1669. }
  1670. delete this._highlightElement;
  1671. },
  1672.  
  1673. _highlightExpression: function(element)
  1674. {
  1675.  
  1676. var tokens = [ element ];
  1677. var token = element.previousSibling;
  1678. while (token && (token.className === "webkit-javascript-ident" || token.className === "source-frame-token" || token.className === "webkit-javascript-keyword" || token.textContent.trim() === ".")) {
  1679. tokens.push(token);
  1680. token = token.previousSibling;
  1681. }
  1682. tokens.reverse();
  1683.  
  1684.  
  1685. var parentElement = element.parentElement;
  1686. var nextElement = element.nextSibling;
  1687. var container = document.createElement("span");
  1688. for (var i = 0; i < tokens.length; ++i)
  1689. container.appendChild(tokens[i]);
  1690. parentElement.insertBefore(container, nextElement);
  1691. return container;
  1692. },
  1693.  
  1694.  
  1695. _addBreakpointDecoration: function(lineNumber, condition, enabled, mutedWhileEditing)
  1696. {
  1697. if (this._preserveDecorations)
  1698. return;
  1699. var breakpoint = {
  1700. condition: condition,
  1701. enabled: enabled
  1702. };
  1703. this.textEditor.setAttribute(lineNumber, "breakpoint", breakpoint);
  1704.  
  1705. var disabled = !enabled || mutedWhileEditing;
  1706. this.textEditor.addBreakpoint(lineNumber, disabled, !!condition);
  1707. },
  1708.  
  1709. _removeBreakpointDecoration: function(lineNumber)
  1710. {
  1711. if (this._preserveDecorations)
  1712. return;
  1713. this.textEditor.removeAttribute(lineNumber, "breakpoint");
  1714. this.textEditor.removeBreakpoint(lineNumber);
  1715. },
  1716.  
  1717. _onKeyDown: function(event)
  1718. {
  1719. if (event.keyIdentifier === "U+001B") { 
  1720. if (this._popoverHelper.isPopoverVisible()) {
  1721. this._popoverHelper.hidePopover();
  1722. event.consume();
  1723. }
  1724. }
  1725. },
  1726.  
  1727.  
  1728. _editBreakpointCondition: function(lineNumber, breakpoint)
  1729. {
  1730. this._conditionElement = this._createConditionElement(lineNumber);
  1731. this.textEditor.addDecoration(lineNumber, this._conditionElement);
  1732.  
  1733. function finishEditing(committed, element, newText)
  1734. {
  1735. this.textEditor.removeDecoration(lineNumber, this._conditionElement);
  1736. delete this._conditionEditorElement;
  1737. delete this._conditionElement;
  1738. if (breakpoint)
  1739. breakpoint.setCondition(newText);
  1740. else
  1741. this._setBreakpoint(lineNumber, newText, true);
  1742. }
  1743.  
  1744. var config = new WebInspector.EditingConfig(finishEditing.bind(this, true), finishEditing.bind(this, false));
  1745. WebInspector.startEditing(this._conditionEditorElement, config);
  1746. this._conditionEditorElement.value = breakpoint ? breakpoint.condition() : "";
  1747. this._conditionEditorElement.select();
  1748. },
  1749.  
  1750. _createConditionElement: function(lineNumber)
  1751. {
  1752. var conditionElement = document.createElement("div");
  1753. conditionElement.className = "source-frame-breakpoint-condition";
  1754.  
  1755. var labelElement = document.createElement("label");
  1756. labelElement.className = "source-frame-breakpoint-message";
  1757. labelElement.htmlFor = "source-frame-breakpoint-condition";
  1758. labelElement.appendChild(document.createTextNode(WebInspector.UIString("The breakpoint on line %d will stop only if this expression is true:", lineNumber)));
  1759. conditionElement.appendChild(labelElement);
  1760.  
  1761. var editorElement = document.createElement("input");
  1762. editorElement.id = "source-frame-breakpoint-condition";
  1763. editorElement.className = "monospace";
  1764. editorElement.type = "text";
  1765. conditionElement.appendChild(editorElement);
  1766. this._conditionEditorElement = editorElement;
  1767.  
  1768. return conditionElement;
  1769. },
  1770.  
  1771.  
  1772. setExecutionLine: function(lineNumber)
  1773. {
  1774. this._executionLineNumber = lineNumber;
  1775. if (this.loaded) {
  1776. this.textEditor.setExecutionLine(lineNumber);
  1777. this.revealLine(this._executionLineNumber);
  1778. if (this.canEditSource())
  1779. this.setSelection(WebInspector.TextRange.createFromLocation(lineNumber, 0));
  1780. }
  1781. },
  1782.  
  1783. clearExecutionLine: function()
  1784. {
  1785. if (this.loaded && typeof this._executionLineNumber === "number")
  1786. this.textEditor.clearExecutionLine();
  1787. delete this._executionLineNumber;
  1788. },
  1789.  
  1790. _lineNumberAfterEditing: function(lineNumber, oldRange, newRange)
  1791. {
  1792. var shiftOffset = lineNumber <= oldRange.startLine ? 0 : newRange.linesCount - oldRange.linesCount;
  1793.  
  1794.  
  1795. if (lineNumber === oldRange.startLine) {
  1796. var whiteSpacesRegex = /^[\s\xA0]*$/;
  1797. for (var i = 0; lineNumber + i <= newRange.endLine; ++i) {
  1798. if (!whiteSpacesRegex.test(this.textEditor.line(lineNumber + i))) {
  1799. shiftOffset = i;
  1800. break;
  1801. }
  1802. }
  1803. }
  1804.  
  1805. var newLineNumber = Math.max(0, lineNumber + shiftOffset);
  1806. if (oldRange.startLine < lineNumber && lineNumber < oldRange.endLine)
  1807. newLineNumber = oldRange.startLine;
  1808. return newLineNumber;
  1809. },
  1810.  
  1811. _breakpointAdded: function(event)
  1812. {
  1813. var uiLocation =   (event.data.uiLocation);
  1814.  
  1815. if (uiLocation.uiSourceCode !== this._uiSourceCode)
  1816. return;
  1817.  
  1818. var breakpoint =   (event.data.breakpoint);
  1819. if (this.loaded)
  1820. this._addBreakpointDecoration(uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled(), false);
  1821. },
  1822.  
  1823. _breakpointRemoved: function(event)
  1824. {
  1825. var uiLocation =   (event.data.uiLocation);
  1826. if (uiLocation.uiSourceCode !== this._uiSourceCode)
  1827. return;
  1828.  
  1829. var breakpoint =   (event.data.breakpoint);
  1830. var remainingBreakpoint = this._breakpointManager.findBreakpoint(this._uiSourceCode, uiLocation.lineNumber);
  1831. if (!remainingBreakpoint && this.loaded)
  1832. this._removeBreakpointDecoration(uiLocation.lineNumber);
  1833. },
  1834.  
  1835. _consoleMessageAdded: function(event)
  1836. {
  1837. var message =   (event.data);
  1838. if (this.loaded)
  1839. this.addMessageToSource(message.lineNumber, message.originalMessage);
  1840. },
  1841.  
  1842. _consoleMessageRemoved: function(event)
  1843. {
  1844. var message =   (event.data);
  1845. if (this.loaded)
  1846. this.removeMessageFromSource(message.lineNumber, message.originalMessage);
  1847. },
  1848.  
  1849. _consoleMessagesCleared: function(event)
  1850. {
  1851. this.clearMessages();
  1852. },
  1853.  
  1854.  
  1855. _onSourceMappingChanged: function(event)
  1856. {
  1857. this._updateScriptFile();
  1858. },
  1859.  
  1860. _updateScriptFile: function()
  1861. {
  1862. if (this._scriptFile) {
  1863. this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.WillMergeToVM, this._willMergeToVM, this);
  1864. this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.DidMergeToVM, this._didMergeToVM, this);
  1865. this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.WillDivergeFromVM, this._willDivergeFromVM, this);
  1866. this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._didDivergeFromVM, this);
  1867. }
  1868. this._scriptFile = this._uiSourceCode.scriptFile();
  1869. if (this._scriptFile) {
  1870. this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.WillMergeToVM, this._willMergeToVM, this);
  1871. this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.DidMergeToVM, this._didMergeToVM, this);
  1872. this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.WillDivergeFromVM, this._willDivergeFromVM, this);
  1873. this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._didDivergeFromVM, this);
  1874. }
  1875. },
  1876.  
  1877. onTextEditorContentLoaded: function()
  1878. {
  1879. if (typeof this._executionLineNumber === "number")
  1880. this.setExecutionLine(this._executionLineNumber);
  1881.  
  1882. var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
  1883. for (var i = 0; i < breakpointLocations.length; ++i) {
  1884. var breakpoint = breakpointLocations[i].breakpoint;
  1885. this._addBreakpointDecoration(breakpointLocations[i].uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled(), false);
  1886. }
  1887.  
  1888. var messages = this._uiSourceCode.consoleMessages();
  1889. for (var i = 0; i < messages.length; ++i) {
  1890. var message = messages[i];
  1891. this.addMessageToSource(message.lineNumber, message.originalMessage);
  1892. }
  1893. },
  1894.  
  1895.  
  1896. _handleGutterClick: function(event)
  1897. {
  1898. if (this._uiSourceCode.isDirty() && !this._supportsEnabledBreakpointsWhileEditing())
  1899. return;
  1900.  
  1901. var lineNumber = event.data.lineNumber;
  1902. var eventObject =   (event.data.event);
  1903.  
  1904. if (eventObject.button != 0 || eventObject.altKey || eventObject.ctrlKey || eventObject.metaKey)
  1905. return;
  1906.  
  1907. this._toggleBreakpoint(lineNumber, eventObject.shiftKey);
  1908. eventObject.consume(true);
  1909. },
  1910.  
  1911.  
  1912. _toggleBreakpoint: function(lineNumber, onlyDisable)
  1913. {
  1914. var breakpoint = this._breakpointManager.findBreakpoint(this._uiSourceCode, lineNumber);
  1915. if (breakpoint) {
  1916. if (onlyDisable)
  1917. breakpoint.setEnabled(!breakpoint.enabled());
  1918. else
  1919. breakpoint.remove();
  1920. } else
  1921. this._setBreakpoint(lineNumber, "", true);
  1922. },
  1923.  
  1924. toggleBreakpointOnCurrentLine: function()
  1925. {
  1926. var selection = this.textEditor.selection();
  1927. if (!selection)
  1928. return;
  1929. this._toggleBreakpoint(selection.startLine, false);
  1930. },
  1931.  
  1932.  
  1933. _setBreakpoint: function(lineNumber, condition, enabled)
  1934. {
  1935. this._breakpointManager.setBreakpoint(this._uiSourceCode, lineNumber, condition, enabled);
  1936. },
  1937.  
  1938.  
  1939. _continueToLine: function(lineNumber)
  1940. {
  1941. var rawLocation =   (this._uiSourceCode.uiLocationToRawLocation(lineNumber, 0));
  1942. WebInspector.debuggerModel.continueToLocation(rawLocation);
  1943. },
  1944.  
  1945. __proto__: WebInspector.SourceFrame.prototype
  1946. }
  1947. ;
  1948.  
  1949.  
  1950.  
  1951. WebInspector.NavigatorOverlayController = function(parentSidebarView, navigatorView, editorView)
  1952. {
  1953. this._parentSidebarView = parentSidebarView;
  1954. this._navigatorView = navigatorView;
  1955. this._editorView = editorView;
  1956.  
  1957. this._navigatorSidebarResizeWidgetElement = document.createElement("div");
  1958. this._navigatorSidebarResizeWidgetElement.addStyleClass("scripts-navigator-resizer-widget");
  1959. this._parentSidebarView.installResizer(this._navigatorSidebarResizeWidgetElement);
  1960. this._navigatorView.element.appendChild(this._navigatorSidebarResizeWidgetElement);
  1961.  
  1962. this._navigatorShowHideButton = new WebInspector.StatusBarButton(WebInspector.UIString("Hide navigator"), "scripts-navigator-show-hide-button", 3);
  1963. this._navigatorShowHideButton.state = "pinned";
  1964. this._navigatorShowHideButton.addEventListener("click", this._toggleNavigator, this);
  1965. this._editorView.element.appendChild(this._navigatorShowHideButton.element);
  1966.  
  1967. WebInspector.settings.navigatorHidden = WebInspector.settings.createSetting("navigatorHidden", true);
  1968. if (WebInspector.settings.navigatorHidden.get())
  1969. this._toggleNavigator();
  1970. }
  1971.  
  1972. WebInspector.NavigatorOverlayController.prototype = {
  1973. wasShown: function()
  1974. {
  1975. window.setTimeout(this._maybeShowNavigatorOverlay.bind(this), 0);
  1976. },
  1977.  
  1978. _maybeShowNavigatorOverlay: function()
  1979. {
  1980. if (WebInspector.settings.navigatorHidden.get() && !WebInspector.settings.navigatorWasOnceHidden.get())
  1981. this.showNavigatorOverlay();
  1982. },
  1983.  
  1984. _toggleNavigator: function()
  1985. {
  1986. if (this._navigatorShowHideButton.state === "overlay")
  1987. this._pinNavigator();
  1988. else if (this._navigatorShowHideButton.state === "hidden")
  1989. this.showNavigatorOverlay();
  1990. else
  1991. this._hidePinnedNavigator();
  1992. },
  1993.  
  1994. _hidePinnedNavigator: function()
  1995. {
  1996. this._navigatorShowHideButton.state = "hidden";
  1997. this._navigatorShowHideButton.title = WebInspector.UIString("Show navigator");
  1998. this._parentSidebarView.element.appendChild(this._navigatorShowHideButton.element);
  1999.  
  2000. this._editorView.element.addStyleClass("navigator-hidden");
  2001. this._navigatorSidebarResizeWidgetElement.addStyleClass("hidden");
  2002.  
  2003. this._parentSidebarView.hideSidebarElement();
  2004. this._navigatorView.detach();
  2005. this._editorView.focus();
  2006.  
  2007. WebInspector.settings.navigatorWasOnceHidden.set(true);
  2008. WebInspector.settings.navigatorHidden.set(true);
  2009. },
  2010.  
  2011. _pinNavigator: function()
  2012. {
  2013. this._navigatorShowHideButton.state = "pinned";
  2014. this._navigatorShowHideButton.title = WebInspector.UIString("Hide navigator");
  2015.  
  2016. this._editorView.element.removeStyleClass("navigator-hidden");
  2017. this._navigatorSidebarResizeWidgetElement.removeStyleClass("hidden");
  2018. this._editorView.element.appendChild(this._navigatorShowHideButton.element);
  2019.  
  2020. this._innerHideNavigatorOverlay();
  2021. this._parentSidebarView.showSidebarElement();
  2022. this._navigatorView.show(this._parentSidebarView.sidebarElement);
  2023. this._navigatorView.focus();
  2024. WebInspector.settings.navigatorHidden.set(false);
  2025. },
  2026.  
  2027. showNavigatorOverlay: function()
  2028. {
  2029. if (this._navigatorShowHideButton.state === "overlay")
  2030. return;
  2031.  
  2032. this._navigatorShowHideButton.state = "overlay";
  2033. this._navigatorShowHideButton.title = WebInspector.UIString("Pin navigator");
  2034.  
  2035. this._sidebarOverlay = new WebInspector.SidebarOverlay(this._navigatorView, "scriptsPanelNavigatorOverlayWidth", Preferences.minScriptsSidebarWidth);
  2036. this._boundKeyDown = this._keyDown.bind(this);
  2037. this._sidebarOverlay.element.addEventListener("keydown", this._boundKeyDown, false);
  2038. var navigatorOverlayResizeWidgetElement = document.createElement("div");
  2039. navigatorOverlayResizeWidgetElement.addStyleClass("scripts-navigator-resizer-widget");
  2040. this._sidebarOverlay.resizerWidgetElement = navigatorOverlayResizeWidgetElement;
  2041.  
  2042. this._navigatorView.element.appendChild(this._navigatorShowHideButton.element);
  2043. this._boundContainingElementFocused = this._containingElementFocused.bind(this);
  2044. this._parentSidebarView.element.addEventListener("mousedown", this._boundContainingElementFocused, false);
  2045.  
  2046. this._sidebarOverlay.show(this._parentSidebarView.element);
  2047. this._navigatorView.focus();
  2048. },
  2049.  
  2050. _keyDown: function(event)
  2051. {
  2052. if (event.handled)
  2053. return;
  2054.  
  2055. if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code) {
  2056. this.hideNavigatorOverlay();
  2057. event.consume(true);
  2058. }
  2059. },
  2060.  
  2061. hideNavigatorOverlay: function()
  2062. {
  2063. if (this._navigatorShowHideButton.state !== "overlay")
  2064. return;
  2065.  
  2066. this._navigatorShowHideButton.state = "hidden";
  2067. this._navigatorShowHideButton.title = WebInspector.UIString("Show navigator");
  2068. this._parentSidebarView.element.appendChild(this._navigatorShowHideButton.element);
  2069.  
  2070. this._innerHideNavigatorOverlay();
  2071. this._editorView.focus();
  2072. },
  2073.  
  2074. _innerHideNavigatorOverlay: function()
  2075. {
  2076. this._parentSidebarView.element.removeEventListener("mousedown", this._boundContainingElementFocused, false);
  2077. this._sidebarOverlay.element.removeEventListener("keydown", this._boundKeyDown, false);
  2078. this._sidebarOverlay.hide();
  2079. },
  2080.  
  2081. _containingElementFocused: function(event)
  2082. {
  2083. if (!event.target.isSelfOrDescendant(this._sidebarOverlay.element))
  2084. this.hideNavigatorOverlay();
  2085. },
  2086.  
  2087. isNavigatorPinned: function()
  2088. {
  2089. return this._navigatorShowHideButton.state === "pinned";
  2090. },
  2091.  
  2092. isNavigatorHidden: function()
  2093. {
  2094. return this._navigatorShowHideButton.state === "hidden";
  2095. }
  2096. }
  2097. ;
  2098.  
  2099.  
  2100.  
  2101. WebInspector.NavigatorView = function()
  2102. {
  2103. WebInspector.View.call(this);
  2104. this.registerRequiredCSS("navigatorView.css");
  2105.  
  2106. this._treeSearchBoxElement = document.createElement("div");
  2107. this._treeSearchBoxElement.className = "navigator-tree-search-box";
  2108. this.element.appendChild(this._treeSearchBoxElement);
  2109.  
  2110. var scriptsTreeElement = document.createElement("ol");
  2111. this._scriptsTree = new WebInspector.NavigatorTreeOutline(this._treeSearchBoxElement, scriptsTreeElement);
  2112.  
  2113. var scriptsOutlineElement = document.createElement("div");
  2114. scriptsOutlineElement.addStyleClass("outline-disclosure");
  2115. scriptsOutlineElement.addStyleClass("navigator");
  2116. scriptsOutlineElement.appendChild(scriptsTreeElement);
  2117.  
  2118. this.element.addStyleClass("fill");
  2119. this.element.addStyleClass("navigator-container");
  2120. this.element.appendChild(scriptsOutlineElement);
  2121. this.setDefaultFocusedElement(this._scriptsTree.element);
  2122.  
  2123. this._folderTreeElements = {};
  2124. this._scriptTreeElementsByUISourceCode = new Map();
  2125.  
  2126. WebInspector.settings.showScriptFolders.addChangeListener(this._showScriptFoldersSettingChanged.bind(this));
  2127. }
  2128.  
  2129.  
  2130. WebInspector.NavigatorView.Events = {
  2131. ItemSelected: "ItemSelected",
  2132. FileRenamed: "FileRenamed"
  2133. }
  2134.  
  2135. WebInspector.NavigatorView.prototype = {
  2136.  
  2137. addUISourceCode: function(uiSourceCode)
  2138. {
  2139. if (this._scriptTreeElementsByUISourceCode.get(uiSourceCode))
  2140. return;
  2141.  
  2142. var scriptTreeElement = new WebInspector.NavigatorSourceTreeElement(this, uiSourceCode, "");
  2143. this._scriptTreeElementsByUISourceCode.put(uiSourceCode, scriptTreeElement);
  2144. this._updateScriptTitle(uiSourceCode);
  2145. this._addUISourceCodeListeners(uiSourceCode);
  2146.  
  2147. var folderTreeElement = this.getOrCreateFolderTreeElement(uiSourceCode);
  2148. folderTreeElement.appendChild(scriptTreeElement);
  2149. },
  2150.  
  2151. _uiSourceCodeTitleChanged: function(event)
  2152. {
  2153. var uiSourceCode =   (event.target);
  2154. this._updateScriptTitle(uiSourceCode)
  2155. },
  2156.  
  2157. _uiSourceCodeWorkingCopyChanged: function(event)
  2158. {
  2159. var uiSourceCode =   (event.target);
  2160. this._updateScriptTitle(uiSourceCode)
  2161. },
  2162.  
  2163. _uiSourceCodeWorkingCopyCommitted: function(event)
  2164. {
  2165. var uiSourceCode =   (event.target);
  2166. this._updateScriptTitle(uiSourceCode)
  2167. },
  2168.  
  2169. _uiSourceCodeFormattedChanged: function(event)
  2170. {
  2171. var uiSourceCode =   (event.target);
  2172. this._updateScriptTitle(uiSourceCode);
  2173. },
  2174.  
  2175.  
  2176. _updateScriptTitle: function(uiSourceCode, ignoreIsDirty)
  2177. {
  2178. var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2179. if (!scriptTreeElement)
  2180. return;
  2181.  
  2182. var titleText;
  2183. if (uiSourceCode.parsedURL.isValid) {
  2184. titleText = uiSourceCode.parsedURL.lastPathComponent;
  2185. if (uiSourceCode.parsedURL.queryParams)
  2186. titleText += "?" + uiSourceCode.parsedURL.queryParams;
  2187. } else if (uiSourceCode.parsedURL)
  2188. titleText = uiSourceCode.parsedURL.url;
  2189. if (!titleText)
  2190. titleText = WebInspector.UIString("(program)");
  2191. if (!ignoreIsDirty && uiSourceCode.isDirty())
  2192. titleText = "*" + titleText;
  2193. scriptTreeElement.titleText = titleText;
  2194. },
  2195.  
  2196.  
  2197. isScriptSourceAdded: function(uiSourceCode)
  2198. {
  2199. var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2200. return !!scriptTreeElement;
  2201. },
  2202.  
  2203.  
  2204. revealUISourceCode: function(uiSourceCode)
  2205. {
  2206. if (this._scriptsTree.selectedTreeElement)
  2207. this._scriptsTree.selectedTreeElement.deselect();
  2208.  
  2209. this._lastSelectedUISourceCode = uiSourceCode;
  2210.  
  2211. var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2212. scriptTreeElement.revealAndSelect(true);
  2213. },
  2214.  
  2215.  
  2216. _scriptSelected: function(uiSourceCode, focusSource)
  2217. {
  2218. this._lastSelectedUISourceCode = uiSourceCode;
  2219. var data = { uiSourceCode: uiSourceCode, focusSource: focusSource};
  2220. this.dispatchEventToListeners(WebInspector.NavigatorView.Events.ItemSelected, data);
  2221. },
  2222.  
  2223.  
  2224. removeUISourceCode: function(uiSourceCode)
  2225. {
  2226. var treeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2227. while (treeElement) {
  2228. var parent = treeElement.parent;
  2229. if (parent) {
  2230. if (treeElement instanceof WebInspector.NavigatorFolderTreeElement)
  2231. delete this._folderTreeElements[treeElement.folderIdentifier];
  2232. parent.removeChild(treeElement);
  2233. if (parent.children.length)
  2234. break;
  2235. }
  2236. treeElement = parent;
  2237. }
  2238. this._scriptTreeElementsByUISourceCode.remove(uiSourceCode);
  2239. this._removeUISourceCodeListeners(uiSourceCode);
  2240. },
  2241.  
  2242.  
  2243. _addUISourceCodeListeners: function(uiSourceCode)
  2244. {
  2245. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
  2246. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
  2247. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
  2248. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
  2249. },
  2250.  
  2251.  
  2252. _removeUISourceCodeListeners: function(uiSourceCode)
  2253. {
  2254. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
  2255. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
  2256. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
  2257. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
  2258. },
  2259.  
  2260. _showScriptFoldersSettingChanged: function()
  2261. {
  2262. var uiSourceCodes = this._scriptsTree.scriptTreeElements();
  2263. this.reset();
  2264.  
  2265. for (var i = 0; i < uiSourceCodes.length; ++i)
  2266. this.addUISourceCode(uiSourceCodes[i]);
  2267.  
  2268. if (this._lastSelectedUISourceCode)
  2269. this.revealUISourceCode(this._lastSelectedUISourceCode);
  2270. },
  2271.  
  2272. _fileRenamed: function(uiSourceCode, newTitle)
  2273. {    
  2274. var data = { uiSourceCode: uiSourceCode, name: newTitle };
  2275. this.dispatchEventToListeners(WebInspector.NavigatorView.Events.FileRenamed, data);
  2276. },
  2277.  
  2278.  
  2279. rename: function(uiSourceCode, callback)
  2280. {
  2281. var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2282. if (!scriptTreeElement)
  2283. return;
  2284.  
  2285.  
  2286. var treeOutlineElement = scriptTreeElement.treeOutline.element;
  2287. WebInspector.markBeingEdited(treeOutlineElement, true);
  2288.  
  2289. function commitHandler(element, newTitle, oldTitle)
  2290. {
  2291. if (newTitle && newTitle !== oldTitle)
  2292. this._fileRenamed(uiSourceCode, newTitle);
  2293. afterEditing.call(this, true);
  2294. }
  2295.  
  2296. function cancelHandler()
  2297. {
  2298. afterEditing.call(this, false);
  2299. }
  2300.  
  2301.  
  2302. function afterEditing(committed)
  2303. {
  2304. WebInspector.markBeingEdited(treeOutlineElement, false);
  2305. this._updateScriptTitle(uiSourceCode);
  2306. if (callback)
  2307. callback(committed);
  2308. }
  2309.  
  2310. var editingConfig = new WebInspector.EditingConfig(commitHandler.bind(this), cancelHandler.bind(this));
  2311. this._updateScriptTitle(uiSourceCode, true);
  2312. WebInspector.startEditing(scriptTreeElement.titleElement, editingConfig);
  2313. window.getSelection().setBaseAndExtent(scriptTreeElement.titleElement, 0, scriptTreeElement.titleElement, 1);
  2314. },
  2315.  
  2316. reset: function()
  2317. {
  2318. var uiSourceCodes = this._scriptsTree.scriptTreeElements;
  2319. for (var i = 0; i < uiSourceCodes.length; ++i)
  2320. this._removeUISourceCodeListeners(uiSourceCodes[i]);
  2321.  
  2322. this._scriptsTree.stopSearch();
  2323. this._scriptsTree.removeChildren();
  2324. this._folderTreeElements = {};
  2325. this._scriptTreeElementsByUISourceCode.clear();
  2326. },
  2327.  
  2328.  
  2329. createFolderTreeElement: function(parentFolderElement, folderIdentifier, domain, folderName)
  2330. {
  2331. var folderTreeElement = new WebInspector.NavigatorFolderTreeElement(folderIdentifier, domain, folderName);
  2332. parentFolderElement.appendChild(folderTreeElement);
  2333. this._folderTreeElements[folderIdentifier] = folderTreeElement;
  2334. return folderTreeElement;
  2335. },
  2336.  
  2337.  
  2338. getOrCreateFolderTreeElement: function(uiSourceCode)
  2339. {
  2340. return this._getOrCreateFolderTreeElement(uiSourceCode.parsedURL.host, uiSourceCode.parsedURL.folderPathComponents);
  2341. },
  2342.  
  2343.  
  2344. _getOrCreateFolderTreeElement: function(domain, folderName)
  2345. {
  2346. var folderIdentifier = domain + "/" + folderName;
  2347.  
  2348. if (this._folderTreeElements[folderIdentifier])
  2349. return this._folderTreeElements[folderIdentifier];
  2350.  
  2351. var showScriptFolders = WebInspector.settings.showScriptFolders.get();
  2352.  
  2353. if ((!domain && !folderName) || !showScriptFolders)
  2354. return this._scriptsTree;
  2355.  
  2356. var parentFolderElement;
  2357. if (!folderName)
  2358. parentFolderElement = this._scriptsTree;
  2359. else
  2360. parentFolderElement = this._getOrCreateFolderTreeElement(domain, "");
  2361.  
  2362. return this.createFolderTreeElement(parentFolderElement, folderIdentifier, domain, folderName);
  2363. },
  2364.  
  2365. handleContextMenu: function(event, uiSourceCode)
  2366. {
  2367. var contextMenu = new WebInspector.ContextMenu(event);
  2368. contextMenu.appendApplicableItems(uiSourceCode);
  2369. contextMenu.show();
  2370. },
  2371.  
  2372. __proto__: WebInspector.View.prototype
  2373. }
  2374.  
  2375.  
  2376. WebInspector.NavigatorTreeOutline = function(treeSearchBoxElement, element)
  2377. {
  2378. TreeOutline.call(this, element);
  2379. this.element = element;
  2380.  
  2381. this._treeSearchBoxElement = treeSearchBoxElement;
  2382.  
  2383. this.comparator = WebInspector.NavigatorTreeOutline._treeElementsCompare;
  2384.  
  2385. this.searchable = true;
  2386. this.searchInputElement = document.createElement("input");
  2387. }
  2388.  
  2389. WebInspector.NavigatorTreeOutline._treeElementsCompare = function compare(treeElement1, treeElement2)
  2390. {
  2391.  
  2392. function typeWeight(treeElement)
  2393. {
  2394. if (treeElement instanceof WebInspector.NavigatorFolderTreeElement) {
  2395. if (treeElement.isDomain) {
  2396. if (treeElement.titleText === WebInspector.inspectedPageDomain)
  2397. return 1;
  2398. return 2;
  2399. }
  2400. return 3;
  2401. }
  2402. return 4;
  2403. }
  2404.  
  2405. var typeWeight1 = typeWeight(treeElement1);
  2406. var typeWeight2 = typeWeight(treeElement2);
  2407.  
  2408. var result;
  2409. if (typeWeight1 > typeWeight2)
  2410. result = 1;
  2411. else if (typeWeight1 < typeWeight2)
  2412. result = -1;
  2413. else {
  2414. var title1 = treeElement1.titleText;
  2415. var title2 = treeElement2.titleText;
  2416. result = title1.localeCompare(title2);
  2417. }
  2418. return result;
  2419. }
  2420.  
  2421. WebInspector.NavigatorTreeOutline.prototype = {
  2422.  
  2423. scriptTreeElements: function()
  2424. {
  2425. var result = [];
  2426. if (this.children.length) {
  2427. for (var treeElement = this.children[0]; treeElement; treeElement = treeElement.traverseNextTreeElement(false, this, true)) {
  2428. if (treeElement instanceof WebInspector.NavigatorSourceTreeElement)
  2429. result.push(treeElement.uiSourceCode);
  2430. }
  2431. }
  2432. return result;
  2433. },
  2434.  
  2435. searchStarted: function()
  2436. {
  2437. this._treeSearchBoxElement.appendChild(this.searchInputElement);
  2438. this._treeSearchBoxElement.addStyleClass("visible");
  2439. },
  2440.  
  2441. searchFinished: function()
  2442. {
  2443. this._treeSearchBoxElement.removeChild(this.searchInputElement);
  2444. this._treeSearchBoxElement.removeStyleClass("visible");
  2445. },
  2446.  
  2447. __proto__: TreeOutline.prototype
  2448. }
  2449.  
  2450.  
  2451. WebInspector.BaseNavigatorTreeElement = function(title, iconClasses, hasChildren, noIcon)
  2452. {
  2453. TreeElement.call(this, "", null, hasChildren);
  2454. this._titleText = title;
  2455. this._iconClasses = iconClasses;
  2456. this._noIcon = noIcon;
  2457. }
  2458.  
  2459. WebInspector.BaseNavigatorTreeElement.prototype = {
  2460. onattach: function()
  2461. {
  2462. this.listItemElement.removeChildren();
  2463. if (this._iconClasses) {
  2464. for (var i = 0; i < this._iconClasses.length; ++i)
  2465. this.listItemElement.addStyleClass(this._iconClasses[i]);
  2466. }
  2467.  
  2468. var selectionElement = document.createElement("div");
  2469. selectionElement.className = "selection";
  2470. this.listItemElement.appendChild(selectionElement);
  2471.  
  2472. if (!this._noIcon) {
  2473. this.imageElement = document.createElement("img");
  2474. this.imageElement.className = "icon";
  2475. this.listItemElement.appendChild(this.imageElement);
  2476. }
  2477.  
  2478. this.titleElement = document.createElement("div");
  2479. this.titleElement.className = "base-navigator-tree-element-title";
  2480. this._titleTextNode = document.createTextNode("");
  2481. this._titleTextNode.textContent = this._titleText;
  2482. this.titleElement.appendChild(this._titleTextNode);
  2483. this.listItemElement.appendChild(this.titleElement);
  2484. this.expand();
  2485. },
  2486.  
  2487. onreveal: function()
  2488. {
  2489. if (this.listItemElement)
  2490. this.listItemElement.scrollIntoViewIfNeeded(true);
  2491. },
  2492.  
  2493.  
  2494. get titleText()
  2495. {
  2496. return this._titleText;
  2497. },
  2498.  
  2499. set titleText(titleText)
  2500. {
  2501. this._titleText = titleText || "";
  2502. if (this.titleElement)
  2503. this.titleElement.textContent = this._titleText;
  2504. },
  2505.  
  2506.  
  2507. matchesSearchText: function(searchText)
  2508. {
  2509. return this.titleText.match(new RegExp("^" + searchText.escapeForRegExp(), "i"));
  2510. },
  2511.  
  2512. __proto__: TreeElement.prototype
  2513. }
  2514.  
  2515.  
  2516. WebInspector.NavigatorFolderTreeElement = function(folderIdentifier, domain, folderName)
  2517. {
  2518. this._folderIdentifier = folderIdentifier;
  2519. this._folderName = folderName;
  2520.  
  2521. var iconClass = this.isDomain ? "navigator-domain-tree-item" : "navigator-folder-tree-item";
  2522. var title = this.isDomain ? domain : folderName.substring(1);
  2523.  
  2524. WebInspector.BaseNavigatorTreeElement.call(this, title, [iconClass], true);
  2525. this.tooltip = folderName;
  2526. }
  2527.  
  2528. WebInspector.NavigatorFolderTreeElement.prototype = {
  2529.  
  2530. get folderIdentifier()
  2531. {
  2532. return this._folderIdentifier;
  2533. },
  2534.  
  2535.  
  2536. get isDomain()
  2537. {
  2538. return this._folderName === "";
  2539. },
  2540.  
  2541. onattach: function()
  2542. {
  2543. WebInspector.BaseNavigatorTreeElement.prototype.onattach.call(this);
  2544. if (this.isDomain && this.titleText != WebInspector.inspectedPageDomain)
  2545. this.collapse();
  2546. else
  2547. this.expand();
  2548. },
  2549.  
  2550. __proto__: WebInspector.BaseNavigatorTreeElement.prototype
  2551. }
  2552.  
  2553.  
  2554. WebInspector.NavigatorSourceTreeElement = function(navigatorView, uiSourceCode, title)
  2555. {
  2556. WebInspector.BaseNavigatorTreeElement.call(this, title, ["navigator-" + uiSourceCode.contentType().name() + "-tree-item"], false);
  2557. this._navigatorView = navigatorView;
  2558. this._uiSourceCode = uiSourceCode;
  2559. this.tooltip = uiSourceCode.url;
  2560. }
  2561.  
  2562. WebInspector.NavigatorSourceTreeElement.prototype = {
  2563.  
  2564. get uiSourceCode()
  2565. {
  2566. return this._uiSourceCode;
  2567. },
  2568.  
  2569. onattach: function()
  2570. {
  2571. WebInspector.BaseNavigatorTreeElement.prototype.onattach.call(this);
  2572. this.listItemElement.draggable = true;
  2573. this.listItemElement.addEventListener("click", this._onclick.bind(this), false);
  2574. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), false);
  2575. this.listItemElement.addEventListener("mousedown", this._onmousedown.bind(this), false);
  2576. this.listItemElement.addEventListener("dragstart", this._ondragstart.bind(this), false);
  2577. },
  2578.  
  2579. _onmousedown: function(event)
  2580. {
  2581. if (event.which === 1) 
  2582. this._uiSourceCode.requestContent(callback.bind(this));
  2583.  
  2584. function callback(content, contentEncoded, mimeType)
  2585. {
  2586. this._warmedUpContent = content;
  2587. }
  2588. },
  2589.  
  2590. _ondragstart: function(event)
  2591. {
  2592. event.dataTransfer.setData("text/plain", this._warmedUpContent);
  2593. event.dataTransfer.effectAllowed = "copy";
  2594. return true;
  2595. },
  2596.  
  2597. onspace: function()
  2598. {
  2599. this._navigatorView._scriptSelected(this.uiSourceCode, true);
  2600. return true;
  2601. },
  2602.  
  2603.  
  2604. _onclick: function(event)
  2605. {
  2606. this._navigatorView._scriptSelected(this.uiSourceCode, false);
  2607. },
  2608.  
  2609.  
  2610. ondblclick: function(event)
  2611. {
  2612. var middleClick = event.button === 1;
  2613. this._navigatorView._scriptSelected(this.uiSourceCode, !middleClick);
  2614. },
  2615.  
  2616. onenter: function()
  2617. {
  2618. this._navigatorView._scriptSelected(this.uiSourceCode, true);
  2619. return true;
  2620. },
  2621.  
  2622.  
  2623. _handleContextMenuEvent: function(event)
  2624. {
  2625. this._navigatorView.handleContextMenu(event, this._uiSourceCode);
  2626. },
  2627.  
  2628. __proto__: WebInspector.BaseNavigatorTreeElement.prototype
  2629. }
  2630. ;
  2631.  
  2632.  
  2633.  
  2634. WebInspector.RevisionHistoryView = function()
  2635. {
  2636. WebInspector.View.call(this);
  2637. this.registerRequiredCSS("revisionHistory.css");
  2638. this.element.addStyleClass("revision-history-drawer");
  2639. this.element.addStyleClass("fill");
  2640. this.element.addStyleClass("outline-disclosure");
  2641. this._uiSourceCodeItems = new Map();
  2642.  
  2643. var olElement = this.element.createChild("ol");
  2644. this._treeOutline = new TreeOutline(olElement);
  2645.  
  2646.  
  2647. function populateRevisions(uiSourceCode)
  2648. {
  2649. if (uiSourceCode.history.length)
  2650. this._createUISourceCodeItem(uiSourceCode);
  2651. }
  2652.  
  2653. WebInspector.workspace.uiSourceCodes().forEach(populateRevisions.bind(this));
  2654. WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeContentCommitted, this._revisionAdded, this);
  2655. WebInspector.workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, this._uiSourceCodeRemoved, this);
  2656. WebInspector.workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeRemoved, this._uiSourceCodeRemoved, this);
  2657. WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
  2658.  
  2659. this._statusElement = document.createElement("span");
  2660. this._statusElement.textContent = WebInspector.UIString("Local modifications");
  2661.  
  2662. }
  2663.  
  2664.  
  2665. WebInspector.RevisionHistoryView.showHistory = function(uiSourceCode)
  2666. {
  2667. if (!WebInspector.RevisionHistoryView._view) 
  2668. WebInspector.RevisionHistoryView._view = new WebInspector.RevisionHistoryView();
  2669. var view = WebInspector.RevisionHistoryView._view;
  2670. WebInspector.showViewInDrawer(view._statusElement, view);
  2671. view._revealUISourceCode(uiSourceCode);
  2672. }
  2673.  
  2674. WebInspector.RevisionHistoryView.prototype = {
  2675.  
  2676. _createUISourceCodeItem: function(uiSourceCode)
  2677. {
  2678. var uiSourceCodeItem = new TreeElement(uiSourceCode.parsedURL.displayName, null, true);
  2679. uiSourceCodeItem.selectable = false;
  2680.  
  2681.  
  2682. for (var i = 0; i < this._treeOutline.children.length; ++i) {
  2683. if (this._treeOutline.children[i].title.localeCompare(uiSourceCode.parsedURL.displayName) > 0) {
  2684. this._treeOutline.insertChild(uiSourceCodeItem, i);
  2685. break;
  2686. }
  2687. }
  2688. if (i === this._treeOutline.children.length)
  2689. this._treeOutline.appendChild(uiSourceCodeItem);
  2690.  
  2691. this._uiSourceCodeItems.put(uiSourceCode, uiSourceCodeItem);
  2692.  
  2693. var revisionCount = uiSourceCode.history.length;
  2694. for (var i = revisionCount - 1; i >= 0; --i) {
  2695. var revision = uiSourceCode.history[i];
  2696. var historyItem = new WebInspector.RevisionHistoryTreeElement(revision, uiSourceCode.history[i - 1], i !== revisionCount - 1);
  2697. uiSourceCodeItem.appendChild(historyItem);
  2698. }
  2699.  
  2700. var linkItem = new TreeElement("", null, false);
  2701. linkItem.selectable = false;
  2702. uiSourceCodeItem.appendChild(linkItem);
  2703.  
  2704. var revertToOriginal = linkItem.listItemElement.createChild("span", "revision-history-link revision-history-link-row");
  2705. revertToOriginal.textContent = WebInspector.UIString("apply original content");
  2706. revertToOriginal.addEventListener("click", uiSourceCode.revertToOriginal.bind(uiSourceCode));
  2707.  
  2708. var clearHistoryElement = uiSourceCodeItem.listItemElement.createChild("span", "revision-history-link");
  2709. clearHistoryElement.textContent = WebInspector.UIString("revert");
  2710. clearHistoryElement.addEventListener("click", this._clearHistory.bind(this, uiSourceCode));
  2711. return uiSourceCodeItem;
  2712. },
  2713.  
  2714.  
  2715. _clearHistory: function(uiSourceCode)
  2716. {
  2717. uiSourceCode.revertAndClearHistory(this._removeUISourceCode.bind(this));
  2718. },
  2719.  
  2720. _revisionAdded: function(event)
  2721. {
  2722. var uiSourceCode =   (event.data.uiSourceCode);
  2723. var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode);
  2724. if (!uiSourceCodeItem) {
  2725. uiSourceCodeItem = this._createUISourceCodeItem(uiSourceCode);
  2726. return;
  2727. }
  2728.  
  2729. var historyLength = uiSourceCode.history.length;
  2730. var historyItem = new WebInspector.RevisionHistoryTreeElement(uiSourceCode.history[historyLength - 1], uiSourceCode.history[historyLength - 2], false);
  2731. if (uiSourceCodeItem.children.length)
  2732. uiSourceCodeItem.children[0].allowRevert();
  2733. uiSourceCodeItem.insertChild(historyItem, 0);
  2734. },
  2735.  
  2736.  
  2737. _revealUISourceCode: function(uiSourceCode)
  2738. {
  2739. var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode);
  2740. if (uiSourceCodeItem) {
  2741. uiSourceCodeItem.reveal();
  2742. uiSourceCodeItem.expand();
  2743. }
  2744. },
  2745.  
  2746. _uiSourceCodeRemoved: function(event)
  2747. {
  2748. var uiSourceCode =   (event.data);
  2749. this._removeUISourceCode(uiSourceCode);
  2750. },
  2751.  
  2752.  
  2753. _removeUISourceCode: function(uiSourceCode)
  2754. {
  2755. var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode);
  2756. if (!uiSourceCodeItem)
  2757. return;
  2758. this._treeOutline.removeChild(uiSourceCodeItem);
  2759. this._uiSourceCodeItems.remove(uiSourceCode);
  2760. },
  2761.  
  2762. _reset: function()
  2763. {
  2764. this._treeOutline.removeChildren();
  2765. this._uiSourceCodeItems.clear();
  2766. },
  2767.  
  2768. __proto__: WebInspector.View.prototype
  2769. }
  2770.  
  2771.  
  2772. WebInspector.RevisionHistoryTreeElement = function(revision, baseRevision, allowRevert)
  2773. {
  2774. TreeElement.call(this, revision.timestamp.toLocaleTimeString(), null, true);
  2775. this.selectable = false;
  2776.  
  2777. this._revision = revision;
  2778. this._baseRevision = baseRevision;
  2779.  
  2780. this._revertElement = document.createElement("span");
  2781. this._revertElement.className = "revision-history-link";
  2782. this._revertElement.textContent = WebInspector.UIString("apply revision content");
  2783. this._revertElement.addEventListener("click", this._revision.revertToThis.bind(this._revision), false);
  2784. if (!allowRevert)
  2785. this._revertElement.addStyleClass("hidden");
  2786. }
  2787.  
  2788. WebInspector.RevisionHistoryTreeElement.prototype = {
  2789. onattach: function()
  2790. {
  2791. this.listItemElement.addStyleClass("revision-history-revision");
  2792. },
  2793.  
  2794. onexpand: function()
  2795. {
  2796. this.listItemElement.appendChild(this._revertElement);
  2797.  
  2798. if (this._wasExpandedOnce)
  2799. return;
  2800. this._wasExpandedOnce = true;
  2801.  
  2802. this.childrenListElement.addStyleClass("source-code");
  2803. if (this._baseRevision)
  2804. this._baseRevision.requestContent(step1.bind(this));
  2805. else
  2806. this._revision.uiSourceCode.requestOriginalContent(step1.bind(this));
  2807.  
  2808. function step1(baseContent)
  2809. {
  2810. this._revision.requestContent(step2.bind(this, baseContent));
  2811. }
  2812.  
  2813. function step2(baseContent, newContent)
  2814. {
  2815. var baseLines = difflib.stringAsLines(baseContent);
  2816. var newLines = difflib.stringAsLines(newContent);
  2817. var sm = new difflib.SequenceMatcher(baseLines, newLines);
  2818. var opcodes = sm.get_opcodes();
  2819. var lastWasSeparator = false;
  2820.  
  2821. for (var idx = 0; idx < opcodes.length; idx++) {
  2822. var code = opcodes[idx];
  2823. var change = code[0];
  2824. var b = code[1];
  2825. var be = code[2];
  2826. var n = code[3];
  2827. var ne = code[4];
  2828. var rowCount = Math.max(be - b, ne - n);
  2829. var topRows = [];
  2830. var bottomRows = [];
  2831. for (var i = 0; i < rowCount; i++) {
  2832. if (change === "delete" || (change === "replace" && b < be)) {
  2833. var lineNumber = b++;
  2834. this._createLine(lineNumber, null, baseLines[lineNumber], "removed");
  2835. lastWasSeparator = false;
  2836. }
  2837.  
  2838. if (change === "insert" || (change === "replace" && n < ne)) {
  2839. var lineNumber = n++;
  2840. this._createLine(null, lineNumber, newLines[lineNumber], "added");
  2841. lastWasSeparator = false;
  2842. }
  2843.  
  2844. if (change === "equal") {
  2845. b++;
  2846. n++;
  2847. if (!lastWasSeparator)
  2848. this._createLine(null, null, "    \u2026", "separator");
  2849. lastWasSeparator = true;
  2850. }
  2851. }
  2852. }
  2853. }
  2854. },
  2855.  
  2856. oncollapse: function()
  2857. {
  2858. if (this._revertElement.parentElement)
  2859. this._revertElement.parentElement.removeChild(this._revertElement);
  2860. },
  2861.  
  2862.  
  2863. _createLine: function(baseLineNumber, newLineNumber, lineContent, changeType)
  2864. {
  2865. var child = new TreeElement("", null, false);
  2866. child.selectable = false;
  2867. this.appendChild(child);
  2868. var lineElement = document.createElement("span");
  2869.  
  2870. function appendLineNumber(lineNumber)
  2871. {
  2872. var numberString = lineNumber !== null ? numberToStringWithSpacesPadding(lineNumber + 1, 4) : "    ";
  2873. var lineNumberSpan = document.createElement("span");
  2874. lineNumberSpan.addStyleClass("webkit-line-number");
  2875. lineNumberSpan.textContent = numberString;
  2876. child.listItemElement.appendChild(lineNumberSpan);
  2877. }
  2878.  
  2879. appendLineNumber(baseLineNumber);
  2880. appendLineNumber(newLineNumber);
  2881.  
  2882. var contentSpan = document.createElement("span");
  2883. contentSpan.textContent = lineContent;
  2884. child.listItemElement.appendChild(contentSpan);
  2885. child.listItemElement.addStyleClass("revision-history-line");
  2886. child.listItemElement.addStyleClass("revision-history-line-" + changeType);
  2887. },
  2888.  
  2889. allowRevert: function()
  2890. {
  2891. this._revertElement.removeStyleClass("hidden");
  2892. },
  2893.  
  2894. __proto__: TreeElement.prototype
  2895. }
  2896. ;
  2897.  
  2898.  
  2899.  
  2900. WebInspector.ScopeChainSidebarPane = function()
  2901. {
  2902. WebInspector.SidebarPane.call(this, WebInspector.UIString("Scope Variables"));
  2903. this._sections = [];
  2904. this._expandedSections = {};
  2905. this._expandedProperties = [];
  2906. }
  2907.  
  2908. WebInspector.ScopeChainSidebarPane.prototype = {
  2909. update: function(callFrame)
  2910. {
  2911. this.bodyElement.removeChildren();
  2912.  
  2913. if (!callFrame) {
  2914. var infoElement = document.createElement("div");
  2915. infoElement.className = "info";
  2916. infoElement.textContent = WebInspector.UIString("Not Paused");
  2917. this.bodyElement.appendChild(infoElement);
  2918. return;
  2919. }
  2920.  
  2921. for (var i = 0; i < this._sections.length; ++i) {
  2922. var section = this._sections[i];
  2923. if (!section.title)
  2924. continue;
  2925. if (section.expanded)
  2926. this._expandedSections[section.title] = true;
  2927. else
  2928. delete this._expandedSections[section.title];
  2929. }
  2930.  
  2931. this._sections = [];
  2932.  
  2933. var foundLocalScope = false;
  2934. var scopeChain = callFrame.scopeChain;
  2935. for (var i = 0; i < scopeChain.length; ++i) {
  2936. var scope = scopeChain[i];
  2937. var title = null;
  2938. var subtitle = scope.object.description;
  2939. var emptyPlaceholder = null;
  2940. var extraProperties = null;
  2941.  
  2942. switch (scope.type) {
  2943. case "local":
  2944. foundLocalScope = true;
  2945. title = WebInspector.UIString("Local");
  2946. emptyPlaceholder = WebInspector.UIString("No Variables");
  2947. subtitle = null;
  2948. if (callFrame.this)
  2949. extraProperties = [ new WebInspector.RemoteObjectProperty("this", WebInspector.RemoteObject.fromPayload(callFrame.this)) ];
  2950. if (i == 0) {
  2951. var details = WebInspector.debuggerModel.debuggerPausedDetails();
  2952. var exception = details.reason === WebInspector.DebuggerModel.BreakReason.Exception ? details.auxData : 0;
  2953. if (exception) {
  2954. extraProperties = extraProperties || [];
  2955. var exceptionObject =   (exception);
  2956. extraProperties.push(new WebInspector.RemoteObjectProperty("<exception>", WebInspector.RemoteObject.fromPayload(exceptionObject)));
  2957. }
  2958. }
  2959. break;
  2960. case "closure":
  2961. title = WebInspector.UIString("Closure");
  2962. emptyPlaceholder = WebInspector.UIString("No Variables");
  2963. subtitle = null;
  2964. break;
  2965. case "catch":
  2966. title = WebInspector.UIString("Catch");
  2967. subtitle = null;
  2968. break;
  2969. case "with":
  2970. title = WebInspector.UIString("With Block");
  2971. break;
  2972. case "global":
  2973. title = WebInspector.UIString("Global");
  2974. break;
  2975. }
  2976.  
  2977. if (!title || title === subtitle)
  2978. subtitle = null;
  2979.  
  2980. var section = new WebInspector.ObjectPropertiesSection(WebInspector.RemoteObject.fromPayload(scope.object), title, subtitle, emptyPlaceholder, true, extraProperties, WebInspector.ScopeVariableTreeElement);
  2981. section.editInSelectedCallFrameWhenPaused = true;
  2982. section.pane = this;
  2983.  
  2984. if (scope.type === "global")
  2985. section.expanded = false;
  2986. else if (!foundLocalScope || scope.type === "local" || title in this._expandedSections)
  2987. section.expanded = true;
  2988.  
  2989. this._sections.push(section);
  2990. this.bodyElement.appendChild(section.element);
  2991. }
  2992. },
  2993.  
  2994. __proto__: WebInspector.SidebarPane.prototype
  2995. }
  2996.  
  2997.  
  2998. WebInspector.ScopeVariableTreeElement = function(property)
  2999. {
  3000. WebInspector.ObjectPropertyTreeElement.call(this, property);
  3001. }
  3002.  
  3003. WebInspector.ScopeVariableTreeElement.prototype = {
  3004. onattach: function()
  3005. {
  3006. WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
  3007. if (this.hasChildren && this.propertyIdentifier in this.treeOutline.section.pane._expandedProperties)
  3008. this.expand();
  3009. },
  3010.  
  3011. onexpand: function()
  3012. {
  3013. this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier] = true;
  3014. },
  3015.  
  3016. oncollapse: function()
  3017. {
  3018. delete this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier];
  3019. },
  3020.  
  3021. get propertyIdentifier()
  3022. {
  3023. if ("_propertyIdentifier" in this)
  3024. return this._propertyIdentifier;
  3025. var section = this.treeOutline.section;
  3026. this._propertyIdentifier = section.title + ":" + (section.subtitle ? section.subtitle + ":" : "") + this.propertyPath();
  3027. return this._propertyIdentifier;
  3028. },
  3029.  
  3030. __proto__: WebInspector.ObjectPropertyTreeElement.prototype
  3031. }
  3032. ;
  3033.  
  3034.  
  3035.  
  3036. WebInspector.ScriptsNavigator = function()
  3037. {
  3038. WebInspector.Object.call(this);
  3039.  
  3040. this._tabbedPane = new WebInspector.TabbedPane();
  3041. this._tabbedPane.shrinkableTabs = true;
  3042. this._tabbedPane.element.addStyleClass("navigator-tabbed-pane");
  3043.  
  3044. this._scriptsView = new WebInspector.NavigatorView();
  3045. this._scriptsView.addEventListener(WebInspector.NavigatorView.Events.ItemSelected, this._scriptSelected, this);
  3046.  
  3047. this._contentScriptsView = new WebInspector.NavigatorView();
  3048. this._contentScriptsView.addEventListener(WebInspector.NavigatorView.Events.ItemSelected, this._scriptSelected, this);
  3049.  
  3050. this._snippetsView = new WebInspector.SnippetsNavigatorView();
  3051. this._snippetsView.addEventListener(WebInspector.NavigatorView.Events.ItemSelected, this._scriptSelected, this);
  3052. this._snippetsView.addEventListener(WebInspector.NavigatorView.Events.FileRenamed, this._fileRenamed, this);
  3053. this._snippetsView.addEventListener(WebInspector.SnippetsNavigatorView.Events.SnippetCreationRequested, this._snippetCreationRequested, this);
  3054. this._snippetsView.addEventListener(WebInspector.SnippetsNavigatorView.Events.ItemRenamingRequested, this._itemRenamingRequested, this);
  3055.  
  3056. this._tabbedPane.appendTab(WebInspector.ScriptsNavigator.ScriptsTab, WebInspector.UIString("Sources"), this._scriptsView);
  3057. this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.ScriptsTab);
  3058. this._tabbedPane.appendTab(WebInspector.ScriptsNavigator.ContentScriptsTab, WebInspector.UIString("Content scripts"), this._contentScriptsView);
  3059. if (WebInspector.experimentsSettings.snippetsSupport.isEnabled())
  3060. this._tabbedPane.appendTab(WebInspector.ScriptsNavigator.SnippetsTab, WebInspector.UIString("Snippets"), this._snippetsView);
  3061. }
  3062.  
  3063. WebInspector.ScriptsNavigator.Events = {
  3064. ScriptSelected: "ScriptSelected",
  3065. SnippetCreationRequested: "SnippetCreationRequested",
  3066. ItemRenamingRequested: "ItemRenamingRequested",
  3067. FileRenamed: "FileRenamed"
  3068. }
  3069.  
  3070. WebInspector.ScriptsNavigator.ScriptsTab = "scripts";
  3071. WebInspector.ScriptsNavigator.ContentScriptsTab = "contentScripts";
  3072. WebInspector.ScriptsNavigator.SnippetsTab = "snippets";
  3073.  
  3074. WebInspector.ScriptsNavigator.prototype = {
  3075.  
  3076. get view()
  3077. {
  3078. return this._tabbedPane;
  3079. },
  3080.  
  3081.  
  3082. _snippetsNavigatorViewForUISourceCode: function(uiSourceCode)
  3083. {
  3084. if (uiSourceCode.isContentScript)
  3085. return this._contentScriptsView;
  3086. else if (uiSourceCode.isSnippet)
  3087. return this._snippetsView;
  3088. else
  3089. return this._scriptsView;
  3090. },
  3091.  
  3092.  
  3093. addUISourceCode: function(uiSourceCode)
  3094. {
  3095. this._snippetsNavigatorViewForUISourceCode(uiSourceCode).addUISourceCode(uiSourceCode);
  3096. },
  3097.  
  3098.  
  3099. removeUISourceCode: function(uiSourceCode)
  3100. {
  3101. this._snippetsNavigatorViewForUISourceCode(uiSourceCode).removeUISourceCode(uiSourceCode);
  3102. },
  3103.  
  3104.  
  3105. isScriptSourceAdded: function(uiSourceCode)
  3106. {
  3107. return this._snippetsNavigatorViewForUISourceCode(uiSourceCode).isScriptSourceAdded(uiSourceCode);
  3108. },
  3109.  
  3110.  
  3111. revealUISourceCode: function(uiSourceCode)
  3112. {
  3113. this._snippetsNavigatorViewForUISourceCode(uiSourceCode).revealUISourceCode(uiSourceCode);
  3114. if (uiSourceCode.isContentScript)
  3115. this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.ContentScriptsTab);
  3116. else if (uiSourceCode.isSnippet)
  3117. this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.SnippetsTab);
  3118. else
  3119. this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.ScriptsTab);
  3120. },
  3121.  
  3122.  
  3123. rename: function(uiSourceCode, callback)
  3124. {
  3125. this._snippetsNavigatorViewForUISourceCode(uiSourceCode).rename(uiSourceCode, callback);
  3126. },
  3127.  
  3128.  
  3129. _scriptSelected: function(event)
  3130. {
  3131. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ScriptSelected, event.data);
  3132. },
  3133.  
  3134.  
  3135. _fileRenamed: function(event)
  3136. {    
  3137. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.FileRenamed, event.data);
  3138. },
  3139.  
  3140.  
  3141. _itemRenamingRequested: function(event)
  3142. {
  3143. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ItemRenamingRequested, event.data);
  3144. },
  3145.  
  3146.  
  3147. _snippetCreationRequested: function(event)
  3148. {    
  3149. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.SnippetCreationRequested, event.data);
  3150. },
  3151.  
  3152. reset: function()
  3153. {
  3154. this._scriptsView.reset();
  3155. this._contentScriptsView.reset();
  3156. this._snippetsView.reset();
  3157. },
  3158.  
  3159. __proto__: WebInspector.Object.prototype
  3160. }
  3161.  
  3162.  
  3163. WebInspector.SnippetsNavigatorView = function()
  3164. {
  3165. WebInspector.NavigatorView.call(this);
  3166. this.element.addEventListener("contextmenu", this.handleContextMenu.bind(this), false);
  3167. }
  3168.  
  3169. WebInspector.SnippetsNavigatorView.Events = {
  3170. SnippetCreationRequested: "SnippetCreationRequested",
  3171. ItemRenamingRequested: "ItemRenamingRequested"
  3172. }
  3173.  
  3174. WebInspector.SnippetsNavigatorView.prototype = {
  3175.  
  3176. getOrCreateFolderTreeElement: function(uiSourceCode)
  3177. {
  3178. return this._scriptsTree;
  3179. },
  3180.  
  3181.  
  3182. handleContextMenu: function(event, uiSourceCode)
  3183. {
  3184. var contextMenu = new WebInspector.ContextMenu(event);
  3185. if (uiSourceCode) {
  3186. contextMenu.appendItem(WebInspector.UIString("Run"), this._handleEvaluateSnippet.bind(this, uiSourceCode));
  3187. contextMenu.appendItem(WebInspector.UIString("Rename"), this._handleRenameSnippet.bind(this, uiSourceCode));
  3188. contextMenu.appendItem(WebInspector.UIString("Remove"), this._handleRemoveSnippet.bind(this, uiSourceCode));
  3189. contextMenu.appendSeparator();
  3190. }
  3191. contextMenu.appendItem(WebInspector.UIString("New"), this._handleCreateSnippet.bind(this));
  3192. contextMenu.show();
  3193. },
  3194.  
  3195.  
  3196. _handleEvaluateSnippet: function(uiSourceCode, event)
  3197. {
  3198. if (!uiSourceCode.isSnippet)
  3199. return;
  3200. WebInspector.scriptSnippetModel.evaluateScriptSnippet(uiSourceCode);
  3201. },
  3202.  
  3203.  
  3204. _handleRenameSnippet: function(uiSourceCode, event)
  3205. {
  3206. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ItemRenamingRequested, uiSourceCode);
  3207. },
  3208.  
  3209.  
  3210. _handleRemoveSnippet: function(uiSourceCode, event)
  3211. {
  3212. if (!uiSourceCode.isSnippet)
  3213. return;
  3214. WebInspector.scriptSnippetModel.deleteScriptSnippet(uiSourceCode);
  3215. },
  3216.  
  3217.  
  3218. _handleCreateSnippet: function(event)
  3219. {
  3220. this._snippetCreationRequested();
  3221. },
  3222.  
  3223. _snippetCreationRequested: function()
  3224. {
  3225. this.dispatchEventToListeners(WebInspector.SnippetsNavigatorView.Events.SnippetCreationRequested, null);
  3226. },
  3227.  
  3228. __proto__: WebInspector.NavigatorView.prototype
  3229. }
  3230. ;
  3231.  
  3232.  
  3233.  
  3234. WebInspector.ScriptsSearchScope = function(uiSourceCodeProvider)
  3235. {
  3236.  
  3237. WebInspector.SearchScope.call(this)
  3238. this._searchId = 0;
  3239. this._uiSourceCodeProvider = uiSourceCodeProvider;
  3240. }
  3241.  
  3242. WebInspector.ScriptsSearchScope.prototype = {
  3243.  
  3244. performSearch: function(searchConfig, searchResultCallback, searchFinishedCallback)
  3245. {
  3246. this.stopSearch();
  3247.  
  3248. var uiSourceCodes = this._sortedUISourceCodes();
  3249. var uiSourceCodeIndex = 0;
  3250.  
  3251. function filterOutContentScripts(uiSourceCode)
  3252. {
  3253. return !uiSourceCode.isContentScript;
  3254. }
  3255.  
  3256. if (!WebInspector.settings.searchInContentScripts.get())
  3257. uiSourceCodes = uiSourceCodes.filter(filterOutContentScripts);
  3258.  
  3259. function continueSearch()
  3260. {
  3261.  
  3262.  
  3263. if (uiSourceCodeIndex < uiSourceCodes.length) {
  3264. var uiSourceCode = uiSourceCodes[uiSourceCodeIndex++];
  3265. uiSourceCode.searchInContent(searchConfig.query, !searchConfig.ignoreCase, searchConfig.isRegex, searchCallbackWrapper.bind(this, this._searchId, uiSourceCode));
  3266. } else 
  3267. searchFinishedCallback(true);
  3268. }
  3269.  
  3270. function searchCallbackWrapper(searchId, uiSourceCode, searchMatches)
  3271. {
  3272. if (searchId !== this._searchId) {
  3273. searchFinishedCallback(false);
  3274. return;
  3275. }
  3276. var searchResult = new WebInspector.FileBasedSearchResultsPane.SearchResult(uiSourceCode, searchMatches);
  3277. searchResultCallback(searchResult);
  3278. if (searchId !== this._searchId) {
  3279. searchFinishedCallback(false);
  3280. return;
  3281. }
  3282. continueSearch.call(this);
  3283. }
  3284.  
  3285. continueSearch.call(this);
  3286. return uiSourceCodes.length;
  3287. },
  3288.  
  3289. stopSearch: function()
  3290. {
  3291. ++this._searchId;
  3292. },
  3293.  
  3294.  
  3295. createSearchResultsPane: function(searchConfig)
  3296. {
  3297. return new WebInspector.FileBasedSearchResultsPane(searchConfig);
  3298. },
  3299.  
  3300.  
  3301. _sortedUISourceCodes: function()
  3302. {
  3303. function filterOutAnonymous(uiSourceCode)
  3304. {
  3305. return !!uiSourceCode.url;
  3306. }
  3307.  
  3308. function comparator(a, b)
  3309. {
  3310. return a.url.localeCompare(b.url);   
  3311. }
  3312.  
  3313. var uiSourceCodes = this._uiSourceCodeProvider.uiSourceCodes();
  3314.  
  3315. uiSourceCodes = uiSourceCodes.filter(filterOutAnonymous);
  3316. uiSourceCodes.sort(comparator);
  3317.  
  3318. return uiSourceCodes;
  3319. },
  3320.  
  3321. __proto__: WebInspector.SearchScope.prototype
  3322. }
  3323. ;
  3324.  
  3325.  
  3326.  
  3327. WebInspector.SnippetJavaScriptSourceFrame = function(scriptsPanel, uiSourceCode)
  3328. {
  3329. WebInspector.JavaScriptSourceFrame.call(this, scriptsPanel, uiSourceCode);
  3330.  
  3331. this._uiSourceCode = uiSourceCode;
  3332. this._runButton = new WebInspector.StatusBarButton(WebInspector.UIString("Run"), "evaluate-snippet-status-bar-item");
  3333. this._runButton.addEventListener("click", this._runButtonClicked, this);
  3334. }
  3335.  
  3336. WebInspector.SnippetJavaScriptSourceFrame.prototype = {
  3337.  
  3338. statusBarItems: function()
  3339. {
  3340. return [this._runButton.element];
  3341. },
  3342.  
  3343. _runButtonClicked: function()
  3344. {
  3345. WebInspector.scriptSnippetModel.evaluateScriptSnippet(this._uiSourceCode);
  3346. },
  3347.  
  3348. __proto__: WebInspector.JavaScriptSourceFrame.prototype
  3349. }
  3350. ;
  3351.  
  3352.  
  3353.  
  3354. WebInspector.StyleSheetOutlineDialog = function(view, uiSourceCode)
  3355. {
  3356. WebInspector.SelectionDialogContentProvider.call(this);
  3357.  
  3358. this._rules = [];
  3359. this._view = view;
  3360. this._uiSourceCode = uiSourceCode;
  3361. }
  3362.  
  3363.  
  3364. WebInspector.StyleSheetOutlineDialog.show = function(view, uiSourceCode)
  3365. {
  3366. if (WebInspector.Dialog.currentInstance())
  3367. return null;
  3368. var delegate = new WebInspector.StyleSheetOutlineDialog(view, uiSourceCode);
  3369. var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(delegate);
  3370. WebInspector.Dialog.show(view.element, filteredItemSelectionDialog);
  3371. }
  3372.  
  3373. WebInspector.StyleSheetOutlineDialog.prototype = {
  3374.  
  3375. itemTitleAt: function(itemIndex)
  3376. {
  3377. return this._rules[itemIndex].selectorText;
  3378. },
  3379.  
  3380.  
  3381. itemSuffixAt: function(itemIndex)
  3382. {
  3383. return "";
  3384. },
  3385.  
  3386.  
  3387. itemSubtitleAt: function(itemIndex)
  3388. {
  3389. return ":" + (this._rules[itemIndex].sourceLine + 1);
  3390. },
  3391.  
  3392.  
  3393. itemKeyAt: function(itemIndex)
  3394. {
  3395. return this._rules[itemIndex].selectorText;
  3396. },
  3397.  
  3398.  
  3399. itemsCount: function()
  3400. {
  3401. return this._rules.length;
  3402. },
  3403.  
  3404.  
  3405. requestItems: function(callback)
  3406. {
  3407. function didGetAllStyleSheets(error, infos)
  3408. {
  3409. if (error) {
  3410. callback(0, 0, 0, 0);
  3411. return;
  3412. }
  3413.  
  3414. for (var i = 0; i < infos.length; ++i) {
  3415. var info = infos[i];
  3416. if (info.sourceURL === this._uiSourceCode.contentURL()) {
  3417. WebInspector.CSSStyleSheet.createForId(info.styleSheetId, didGetStyleSheet.bind(this));
  3418. return;
  3419. }
  3420. }
  3421. callback(0, 0, 0, 0);
  3422. }
  3423.  
  3424. CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
  3425.  
  3426.  
  3427. function didGetStyleSheet(styleSheet)
  3428. {
  3429. if (!styleSheet) {
  3430. callback(0, 0, 0, 0);
  3431. return;
  3432. }
  3433.  
  3434. this._rules = styleSheet.rules;
  3435. callback(0, this._rules.length, 0, 1);
  3436. }
  3437. },
  3438.  
  3439.  
  3440. selectItem: function(itemIndex, promptValue)
  3441. {
  3442. var lineNumber = this._rules[itemIndex].sourceLine;
  3443. if (!isNaN(lineNumber) && lineNumber >= 0)
  3444. this._view.highlightLine(lineNumber);
  3445. this._view.focus();
  3446. },
  3447.  
  3448.  
  3449. rewriteQuery: function(query)
  3450. {
  3451. return query;
  3452. },
  3453.  
  3454. __proto__: WebInspector.SelectionDialogContentProvider.prototype
  3455. }
  3456. ;
  3457.  
  3458.  
  3459.  
  3460. WebInspector.TabbedEditorContainerDelegate = function() { }
  3461.  
  3462. WebInspector.TabbedEditorContainerDelegate.prototype = {
  3463.  
  3464. viewForFile: function(uiSourceCode) { }
  3465. }
  3466.  
  3467.  
  3468. WebInspector.TabbedEditorContainer = function(delegate, settingName)
  3469. {
  3470. WebInspector.Object.call(this);
  3471. this._delegate = delegate;
  3472.  
  3473. this._tabbedPane = new WebInspector.TabbedPane();
  3474. this._tabbedPane.closeableTabs = true;
  3475. this._tabbedPane.element.id = "scripts-editor-container-tabbed-pane";
  3476.  
  3477. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabClosed, this._tabClosed, this);
  3478. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  3479.  
  3480. this._tabIds = new Map();
  3481. this._files = {};
  3482. this._loadedURLs = {};
  3483.  
  3484. this._previouslyViewedFilesSetting = WebInspector.settings.createSetting(settingName, []);
  3485. this._history = WebInspector.TabbedEditorContainer.History.fromObject(this._previouslyViewedFilesSetting.get());
  3486. }
  3487.  
  3488.  
  3489. WebInspector.TabbedEditorContainer.Events = {
  3490. EditorSelected: "EditorSelected",
  3491. EditorClosed: "EditorClosed"
  3492. }
  3493.  
  3494. WebInspector.TabbedEditorContainer._tabId = 0;
  3495.  
  3496. WebInspector.TabbedEditorContainer.maximalPreviouslyViewedFilesCount = 30;
  3497.  
  3498. WebInspector.TabbedEditorContainer.prototype = {
  3499.  
  3500. get view()
  3501. {
  3502. return this._tabbedPane;
  3503. },
  3504.  
  3505.  
  3506. get visibleView()
  3507. {
  3508. return this._tabbedPane.visibleView;
  3509. },
  3510.  
  3511.  
  3512. show: function(parentElement)
  3513. {
  3514. this._tabbedPane.show(parentElement);
  3515. },
  3516.  
  3517.  
  3518. showFile: function(uiSourceCode)
  3519. {
  3520. this._innerShowFile(uiSourceCode, true);
  3521. },
  3522.  
  3523. _addScrollAndSelectionListeners: function()
  3524. {
  3525. console.assert(this._currentFile);
  3526. var sourceFrame = this._delegate.viewForFile(this._currentFile);
  3527. sourceFrame.addEventListener(WebInspector.SourceFrame.Events.ScrollChanged, this._scrollChanged, this);
  3528. sourceFrame.addEventListener(WebInspector.SourceFrame.Events.SelectionChanged, this._selectionChanged, this);
  3529. },
  3530.  
  3531. _removeScrollAndSelectionListeners: function()
  3532. {
  3533. if (!this._currentFile)
  3534. return;
  3535. var sourceFrame = this._delegate.viewForFile(this._currentFile);
  3536. sourceFrame.removeEventListener(WebInspector.SourceFrame.Events.ScrollChanged, this._scrollChanged, this);
  3537. sourceFrame.removeEventListener(WebInspector.SourceFrame.Events.SelectionChanged, this._selectionChanged, this);
  3538. },
  3539.  
  3540. _scrollChanged: function(event)
  3541. {
  3542. var lineNumber =   (event.data);
  3543. this._history.updateScrollLineNumber(this._currentFile.url, lineNumber);
  3544. this._history.save(this._previouslyViewedFilesSetting);
  3545. },
  3546.  
  3547. _selectionChanged: function(event)
  3548. {
  3549. var range =   (event.data);
  3550. this._history.updateSelectionRange(this._currentFile.url, range);
  3551. this._history.save(this._previouslyViewedFilesSetting);
  3552. },
  3553.  
  3554.  
  3555. _innerShowFile: function(uiSourceCode, userGesture)
  3556. {
  3557. if (this._currentFile === uiSourceCode)
  3558. return;
  3559. this._removeScrollAndSelectionListeners();
  3560. this._currentFile = uiSourceCode;
  3561.  
  3562. var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCode, userGesture);
  3563.  
  3564. this._tabbedPane.selectTab(tabId, userGesture);
  3565. if (userGesture)
  3566. this._editorSelectedByUserAction();
  3567.  
  3568. this._addScrollAndSelectionListeners();
  3569.  
  3570. this.dispatchEventToListeners(WebInspector.TabbedEditorContainer.Events.EditorSelected, this._currentFile);
  3571. },
  3572.  
  3573.  
  3574. _titleForFile: function(uiSourceCode)
  3575. {
  3576. const maxDisplayNameLength = 30;
  3577. const minDisplayQueryParamLength = 5;
  3578.  
  3579. var title;
  3580. var parsedURL = uiSourceCode.parsedURL;
  3581. if (!parsedURL.isValid)
  3582. title = parsedURL.url ? parsedURL.url.trimMiddle(maxDisplayNameLength) : WebInspector.UIString("(program)");
  3583. else {
  3584. var maxDisplayQueryParamLength = Math.max(minDisplayQueryParamLength, maxDisplayNameLength - parsedURL.lastPathComponent.length);
  3585. var displayQueryParams = parsedURL.queryParams ? "?" + parsedURL.queryParams.trimEnd(maxDisplayQueryParamLength - 1) : "";
  3586. var displayLastPathComponent = parsedURL.lastPathComponent.trimMiddle(maxDisplayNameLength - displayQueryParams.length);
  3587. var displayName = displayLastPathComponent + displayQueryParams;
  3588. title = displayName || WebInspector.UIString("(program)");
  3589. }
  3590.  
  3591. if (uiSourceCode.isDirty())
  3592. title += "*";
  3593. return title;
  3594. },
  3595.  
  3596.  
  3597. addUISourceCode: function(uiSourceCode)
  3598. {
  3599. if (this._userSelectedFiles || this._loadedURLs[uiSourceCode.url])
  3600. return;
  3601. this._loadedURLs[uiSourceCode.url] = true;
  3602.  
  3603. var index = this._history.index(uiSourceCode.url)
  3604. if (index === -1)
  3605. return;
  3606.  
  3607. var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCode, false);
  3608.  
  3609.  
  3610. if (index === 0)
  3611. this._innerShowFile(uiSourceCode, false);
  3612. },
  3613.  
  3614.  
  3615. removeUISourceCode: function(uiSourceCode)
  3616. {
  3617. var wasCurrent = this._currentFile === uiSourceCode;
  3618.  
  3619. var tabId = this._tabIds.get(uiSourceCode);
  3620. if (tabId)
  3621. this._tabbedPane.closeTab(tabId);
  3622.  
  3623. if (wasCurrent && uiSourceCode.isTemporary) {
  3624. var newUISourceCode = WebInspector.workspace.uiSourceCodeForURL(uiSourceCode.url);
  3625. if (newUISourceCode)
  3626. this._innerShowFile(newUISourceCode, false);
  3627. }
  3628. },
  3629.  
  3630.  
  3631. _editorClosedByUserAction: function(uiSourceCode)
  3632. {
  3633. this._userSelectedFiles = true;
  3634. this._history.remove(uiSourceCode.url);
  3635. this._updateHistory();
  3636. },
  3637.  
  3638. _editorSelectedByUserAction: function()
  3639. {
  3640. this._userSelectedFiles = true;
  3641. this._updateHistory();
  3642. },
  3643.  
  3644. _updateHistory: function()
  3645. {
  3646. var tabIds = this._tabbedPane.lastOpenedTabIds(WebInspector.TabbedEditorContainer.maximalPreviouslyViewedFilesCount);
  3647.  
  3648. function tabIdToURL(tabId)
  3649. {
  3650. return this._files[tabId].url;
  3651. }
  3652.  
  3653. this._history.update(tabIds.map(tabIdToURL.bind(this)));
  3654. this._history.save(this._previouslyViewedFilesSetting);
  3655. },
  3656.  
  3657.  
  3658. _tooltipForFile: function(uiSourceCode)
  3659. {
  3660. return uiSourceCode.url;
  3661. },
  3662.  
  3663.  
  3664. _appendFileTab: function(uiSourceCode, userGesture)
  3665. {
  3666. var view = this._delegate.viewForFile(uiSourceCode);
  3667. var title = this._titleForFile(uiSourceCode);
  3668. var tooltip = this._tooltipForFile(uiSourceCode);
  3669.  
  3670. var tabId = this._generateTabId();
  3671. this._tabIds.put(uiSourceCode, tabId);
  3672. this._files[tabId] = uiSourceCode;
  3673.  
  3674. var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode.url);
  3675. if (savedScrollLineNumber)
  3676. view.scrollToLine(savedScrollLineNumber);
  3677. var savedSelectionRange = this._history.selectionRange(uiSourceCode.url);
  3678. if (savedSelectionRange)
  3679. view.setSelection(savedSelectionRange);
  3680.  
  3681. this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture);
  3682.  
  3683. this._addUISourceCodeListeners(uiSourceCode);
  3684. return tabId;
  3685. },
  3686.  
  3687.  
  3688. _tabClosed: function(event)
  3689. {
  3690. var tabId =   (event.data.tabId);
  3691. var userGesture =   (event.data.isUserGesture);
  3692.  
  3693. var uiSourceCode = this._files[tabId];
  3694. if (this._currentFile === uiSourceCode) {
  3695. this._removeScrollAndSelectionListeners();
  3696. delete this._currentFile;
  3697. }
  3698. this._tabIds.remove(uiSourceCode);
  3699. delete this._files[tabId];
  3700.  
  3701. this._removeUISourceCodeListeners(uiSourceCode);
  3702.  
  3703. this.dispatchEventToListeners(WebInspector.TabbedEditorContainer.Events.EditorClosed, uiSourceCode);
  3704.  
  3705. if (userGesture)
  3706. this._editorClosedByUserAction(uiSourceCode);
  3707. },
  3708.  
  3709.  
  3710. _tabSelected: function(event)
  3711. {
  3712. var tabId =   (event.data.tabId);
  3713. var userGesture =   (event.data.isUserGesture);
  3714.  
  3715. var uiSourceCode = this._files[tabId];
  3716. this._innerShowFile(uiSourceCode, userGesture);
  3717. },
  3718.  
  3719.  
  3720. _addUISourceCodeListeners: function(uiSourceCode)
  3721. {
  3722. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
  3723. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
  3724. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
  3725. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
  3726. },
  3727.  
  3728.  
  3729. _removeUISourceCodeListeners: function(uiSourceCode)
  3730. {
  3731. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
  3732. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
  3733. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
  3734. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
  3735. },
  3736.  
  3737.  
  3738. _updateFileTitle: function(uiSourceCode)
  3739. {
  3740. var tabId = this._tabIds.get(uiSourceCode);
  3741. if (tabId) {
  3742. var title = this._titleForFile(uiSourceCode);
  3743. this._tabbedPane.changeTabTitle(tabId, title);
  3744. }
  3745. },
  3746.  
  3747. _uiSourceCodeTitleChanged: function(event)
  3748. {
  3749. var uiSourceCode =   (event.target);
  3750. this._updateFileTitle(uiSourceCode);
  3751. },
  3752.  
  3753. _uiSourceCodeWorkingCopyChanged: function(event)
  3754. {
  3755. var uiSourceCode =   (event.target);
  3756. this._updateFileTitle(uiSourceCode);
  3757. },
  3758.  
  3759. _uiSourceCodeWorkingCopyCommitted: function(event)
  3760. {
  3761. var uiSourceCode =   (event.target);
  3762. this._updateFileTitle(uiSourceCode);
  3763. },
  3764.  
  3765. _uiSourceCodeFormattedChanged: function(event)
  3766. {
  3767. var uiSourceCode =   (event.target);
  3768. this._updateFileTitle(uiSourceCode);
  3769. },
  3770.  
  3771. reset: function()
  3772. {
  3773. this._tabbedPane.closeAllTabs();
  3774. this._tabIds = new Map();
  3775. this._files = {};
  3776. delete this._currentFile;
  3777. delete this._userSelectedFiles;
  3778. this._loadedURLs = {};
  3779. },
  3780.  
  3781.  
  3782. _generateTabId: function()
  3783. {
  3784. return "tab_" + (WebInspector.TabbedEditorContainer._tabId++);
  3785. },
  3786.  
  3787.  
  3788. currentFile: function()
  3789. {
  3790. return this._currentFile;
  3791. },
  3792.  
  3793. __proto__: WebInspector.Object.prototype
  3794. }
  3795.  
  3796.  
  3797. WebInspector.TabbedEditorContainer.HistoryItem = function(url, selectionRange, scrollLineNumber)
  3798. {
  3799. this.url = url;
  3800. this.selectionRange = selectionRange;
  3801. this.scrollLineNumber = scrollLineNumber;
  3802. }
  3803.  
  3804.  
  3805. WebInspector.TabbedEditorContainer.HistoryItem.fromObject = function (serializedHistoryItem)
  3806. {
  3807. var selectionRange = serializedHistoryItem.selectionRange ? WebInspector.TextRange.fromObject(serializedHistoryItem.selectionRange) : null;
  3808. return new WebInspector.TabbedEditorContainer.HistoryItem(serializedHistoryItem.url, selectionRange, serializedHistoryItem.scrollLineNumber);
  3809. }
  3810.  
  3811. WebInspector.TabbedEditorContainer.HistoryItem.prototype = {
  3812.  
  3813. serializeToObject: function()
  3814. {
  3815. var serializedHistoryItem = {};
  3816. serializedHistoryItem.url = this.url;
  3817. serializedHistoryItem.selectionRange = this.selectionRange;
  3818. serializedHistoryItem.scrollLineNumber = this.scrollLineNumber;
  3819. return serializedHistoryItem;
  3820. },
  3821.  
  3822. __proto__: WebInspector.Object.prototype
  3823. }
  3824.  
  3825.  
  3826. WebInspector.TabbedEditorContainer.History = function(items)
  3827. {
  3828. this._items = items;
  3829. }
  3830.  
  3831.  
  3832. WebInspector.TabbedEditorContainer.History.fromObject = function(serializedHistory)
  3833. {
  3834. var items = [];
  3835. for (var i = 0; i < serializedHistory.length; ++i)
  3836. items.push(WebInspector.TabbedEditorContainer.HistoryItem.fromObject(serializedHistory[i]));
  3837. return new WebInspector.TabbedEditorContainer.History(items);
  3838. }
  3839.  
  3840. WebInspector.TabbedEditorContainer.History.prototype = {
  3841.  
  3842. index: function(url)
  3843. {
  3844. for (var i = 0; i < this._items.length; ++i) {
  3845. if (this._items[i].url === url)
  3846. return i;
  3847. }
  3848. return -1;
  3849. },
  3850.  
  3851.  
  3852. selectionRange: function(url)
  3853. {
  3854. var index = this.index(url);
  3855. return index !== -1 ? this._items[index].selectionRange : undefined;
  3856. },
  3857.  
  3858.  
  3859. updateSelectionRange: function(url, selectionRange)
  3860. {
  3861. if (!selectionRange)
  3862. return;
  3863. var index = this.index(url);
  3864. if (index === -1)
  3865. return;
  3866. this._items[index].selectionRange = selectionRange;
  3867. },
  3868.  
  3869.  
  3870. scrollLineNumber: function(url)
  3871. {
  3872. var index = this.index(url);
  3873. return index !== -1 ? this._items[index].scrollLineNumber : undefined;
  3874. },
  3875.  
  3876.  
  3877. updateScrollLineNumber: function(url, scrollLineNumber)
  3878. {
  3879. var index = this.index(url);
  3880. if (index === -1)
  3881. return;
  3882. this._items[index].scrollLineNumber = scrollLineNumber;
  3883. },
  3884.  
  3885.  
  3886. update: function(urls)
  3887. {
  3888. for (var i = urls.length - 1; i >= 0; --i) {
  3889. var index = this.index(urls[i]);
  3890. var item;
  3891. if (index !== -1) {
  3892. item = this._items[index];
  3893. this._items.splice(index, 1);
  3894. } else
  3895. item = new WebInspector.TabbedEditorContainer.HistoryItem(urls[i]);
  3896. this._items.unshift(item);
  3897. }
  3898. },
  3899.  
  3900.  
  3901. remove: function(url)
  3902. {
  3903. var index = this.index(url);
  3904. if (index !== -1)
  3905. this._items.splice(index, 1);
  3906. },
  3907.  
  3908.  
  3909. save: function(setting)
  3910. {
  3911. setting.set(this._serializeToObject());
  3912. },
  3913.  
  3914.  
  3915. _serializeToObject: function()
  3916. {
  3917. var serializedHistory = [];
  3918. for (var i = 0; i < this._items.length; ++i)
  3919. serializedHistory.push(this._items[i].serializeToObject());
  3920. return serializedHistory;
  3921. },
  3922.  
  3923. __proto__: WebInspector.Object.prototype
  3924. }
  3925. ;
  3926.  
  3927.  
  3928.  
  3929. WebInspector.UISourceCodeFrame = function(uiSourceCode)
  3930. {
  3931. this._uiSourceCode = uiSourceCode;
  3932. WebInspector.SourceFrame.call(this, this._uiSourceCode);
  3933. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._onFormattedChanged, this);
  3934. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
  3935. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
  3936. }
  3937.  
  3938. WebInspector.UISourceCodeFrame.prototype = {
  3939.  
  3940. canEditSource: function()
  3941. {
  3942. return true;
  3943. },
  3944.  
  3945.  
  3946. commitEditing: function(text)
  3947. {
  3948. if (!this._uiSourceCode.isDirty())
  3949. return;
  3950.  
  3951. this._isCommittingEditing = true;
  3952. this._uiSourceCode.commitWorkingCopy(this._didEditContent.bind(this));
  3953. delete this._isCommittingEditing;
  3954. },
  3955.  
  3956. onTextChanged: function(oldRange, newRange)
  3957. {
  3958. this._isSettingWorkingCopy = true;
  3959. this._uiSourceCode.setWorkingCopy(this._textEditor.text());
  3960. delete this._isSettingWorkingCopy;
  3961. },
  3962.  
  3963. _didEditContent: function(error)
  3964. {
  3965. if (error) {
  3966. WebInspector.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true);
  3967. return;
  3968. }
  3969. },
  3970.  
  3971.  
  3972. _onFormattedChanged: function(event)
  3973. {
  3974. var content =   (event.data.content);
  3975. this._textEditor.setReadOnly(this._uiSourceCode.formatted());
  3976. this._innerSetContent(content);
  3977. },
  3978.  
  3979.  
  3980. _onWorkingCopyChanged: function(event)
  3981. {
  3982. this._innerSetContent(this._uiSourceCode.workingCopy());
  3983. },
  3984.  
  3985.  
  3986. _onWorkingCopyCommitted: function(event)
  3987. {
  3988. this._innerSetContent(this._uiSourceCode.workingCopy());
  3989. },
  3990.  
  3991. _innerSetContent: function(content)
  3992. {
  3993. if (this._isSettingWorkingCopy || this._isCommittingEditing)
  3994. return;
  3995.  
  3996. this.setContent(this._uiSourceCode.content() || "", false, this._uiSourceCode.contentType().canonicalMimeType());
  3997. },
  3998.  
  3999. populateTextAreaContextMenu: function(contextMenu, lineNumber)
  4000. {
  4001. WebInspector.SourceFrame.prototype.populateTextAreaContextMenu.call(this, contextMenu, lineNumber);
  4002. contextMenu.appendApplicableItems(this._uiSourceCode);
  4003. contextMenu.appendSeparator();
  4004. },
  4005.  
  4006. __proto__: WebInspector.SourceFrame.prototype
  4007. }
  4008. ;
  4009.  
  4010.  
  4011.  
  4012. WebInspector.WatchExpressionsSidebarPane = function()
  4013. {
  4014. WebInspector.SidebarPane.call(this, WebInspector.UIString("Watch Expressions"));
  4015. }
  4016.  
  4017. WebInspector.WatchExpressionsSidebarPane.prototype = {
  4018. show: function()
  4019. {
  4020. this._visible = true;
  4021.  
  4022.  
  4023. if (this._wasShown) {
  4024. this._refreshExpressionsIfNeeded();
  4025. return;
  4026. }
  4027.  
  4028. this._wasShown = true;
  4029.  
  4030. this.section = new WebInspector.WatchExpressionsSection();
  4031. this.bodyElement.appendChild(this.section.element);
  4032.  
  4033. var refreshButton = document.createElement("button");
  4034. refreshButton.className = "pane-title-button refresh";
  4035. refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this), false);
  4036. refreshButton.title = WebInspector.UIString("Refresh");
  4037. this.titleElement.appendChild(refreshButton);
  4038.  
  4039. var addButton = document.createElement("button");
  4040. addButton.className = "pane-title-button add";
  4041. addButton.addEventListener("click", this._addButtonClicked.bind(this), false);
  4042. this.titleElement.appendChild(addButton);
  4043. addButton.title = WebInspector.UIString("Add watch expression");
  4044. this._requiresUpdate = true;
  4045.  
  4046. if (WebInspector.settings.watchExpressions.get().length > 0)
  4047. this.expanded = true;
  4048. },
  4049.  
  4050. hide: function()
  4051. {
  4052. this._visible = false;
  4053. },
  4054.  
  4055. reset: function()
  4056. {
  4057. this.refreshExpressions();
  4058. },
  4059.  
  4060. refreshExpressions: function()
  4061. {
  4062. this._requiresUpdate = true;
  4063. this._refreshExpressionsIfNeeded();
  4064. },
  4065.  
  4066. addExpression: function(expression)
  4067. {
  4068. this.section.addExpression(expression);
  4069. this.expanded = true;
  4070. },
  4071.  
  4072. _refreshExpressionsIfNeeded: function()
  4073. {
  4074. if (this._requiresUpdate && this._visible) {
  4075. this.section.update();
  4076. delete this._requiresUpdate;
  4077. } else
  4078. this._requiresUpdate = true;
  4079. },
  4080.  
  4081. _addButtonClicked: function(event)
  4082. {
  4083. event.consume();
  4084. this.expanded = true;
  4085. this.section.addNewExpressionAndEdit();
  4086. },
  4087.  
  4088. _refreshButtonClicked: function(event)
  4089. {
  4090. event.consume();
  4091. this.refreshExpressions();
  4092. },
  4093.  
  4094. __proto__: WebInspector.SidebarPane.prototype
  4095. }
  4096.  
  4097.  
  4098. WebInspector.WatchExpressionsSection = function()
  4099. {
  4100. this._watchObjectGroupId = "watch-group";
  4101.  
  4102. WebInspector.ObjectPropertiesSection.call(this, WebInspector.RemoteObject.fromPrimitiveValue(""));
  4103.  
  4104. this.treeElementConstructor = WebInspector.WatchedPropertyTreeElement;
  4105. this._expandedExpressions = {};
  4106. this._expandedProperties = {};
  4107.  
  4108. this.emptyElement = document.createElement("div");
  4109. this.emptyElement.className = "info";
  4110. this.emptyElement.textContent = WebInspector.UIString("No Watch Expressions");
  4111.  
  4112. this.watchExpressions = WebInspector.settings.watchExpressions.get();
  4113.  
  4114. this.headerElement.className = "hidden";
  4115. this.editable = true;
  4116. this.expanded = true;
  4117. this.propertiesElement.addStyleClass("watch-expressions");
  4118.  
  4119. this.element.addEventListener("mousemove", this._mouseMove.bind(this), true);
  4120. this.element.addEventListener("mouseout", this._mouseOut.bind(this), true);
  4121. this.element.addEventListener("dblclick", this._sectionDoubleClick.bind(this), false);
  4122. this.emptyElement.addEventListener("contextmenu", this._emptyElementContextMenu.bind(this), false);
  4123. }
  4124.  
  4125. WebInspector.WatchExpressionsSection.NewWatchExpression = "\xA0";
  4126.  
  4127. WebInspector.WatchExpressionsSection.prototype = {
  4128. update: function(e)
  4129. {
  4130. if (e)
  4131. e.consume();
  4132.  
  4133. function appendResult(expression, watchIndex, result, wasThrown)
  4134. {
  4135. if (!result)
  4136. return;
  4137.  
  4138. var property = new WebInspector.RemoteObjectProperty(expression, result);
  4139. property.watchIndex = watchIndex;
  4140. property.wasThrown = wasThrown;
  4141.  
  4142.  
  4143.  
  4144.  
  4145.  
  4146.  
  4147.  
  4148.  
  4149. properties.push(property);
  4150.  
  4151. if (properties.length == propertyCount) {
  4152. this.updateProperties(properties, WebInspector.WatchExpressionTreeElement, WebInspector.WatchExpressionsSection.CompareProperties);
  4153.  
  4154.  
  4155.  
  4156. if (this._newExpressionAdded) {
  4157. delete this._newExpressionAdded;
  4158.  
  4159. var treeElement = this.findAddedTreeElement();
  4160. if (treeElement)
  4161. treeElement.startEditing();
  4162. }
  4163.  
  4164.  
  4165. if (this._lastMouseMovePageY)
  4166. this._updateHoveredElement(this._lastMouseMovePageY);
  4167. }
  4168. }
  4169.  
  4170.  
  4171. RuntimeAgent.releaseObjectGroup(this._watchObjectGroupId)
  4172. var properties = [];
  4173.  
  4174.  
  4175.  
  4176. var propertyCount = 0;
  4177. for (var i = 0; i < this.watchExpressions.length; ++i) {
  4178. if (!this.watchExpressions[i])
  4179. continue;
  4180. ++propertyCount;
  4181. }
  4182.  
  4183.  
  4184.  
  4185. for (var i = 0; i < this.watchExpressions.length; ++i) {
  4186. var expression = this.watchExpressions[i];
  4187. if (!expression)
  4188. continue;
  4189.  
  4190. WebInspector.runtimeModel.evaluate(expression, this._watchObjectGroupId, false, true, false, false, appendResult.bind(this, expression, i));
  4191. }
  4192.  
  4193. if (!propertyCount) {
  4194. if (!this.emptyElement.parentNode)
  4195. this.element.appendChild(this.emptyElement);
  4196. } else {
  4197. if (this.emptyElement.parentNode)
  4198. this.element.removeChild(this.emptyElement);
  4199. }
  4200.  
  4201.  
  4202.  
  4203.  
  4204. this.expanded = (propertyCount != 0);
  4205. },
  4206.  
  4207. addExpression: function(expression)
  4208. {
  4209. this.watchExpressions.push(expression);
  4210. this.saveExpressions();
  4211. this.update();
  4212. },
  4213.  
  4214. addNewExpressionAndEdit: function()
  4215. {
  4216. this._newExpressionAdded = true;
  4217. this.watchExpressions.push(WebInspector.WatchExpressionsSection.NewWatchExpression);
  4218. this.update();
  4219. },
  4220.  
  4221. _sectionDoubleClick: function(event)
  4222. {
  4223. if (event.target !== this.element && event.target !== this.propertiesElement && event.target !== this.emptyElement)
  4224. return;
  4225. event.consume();
  4226. this.addNewExpressionAndEdit();
  4227. },
  4228.  
  4229. updateExpression: function(element, value)
  4230. {
  4231. if (value === null) {
  4232. var index = element.property.watchIndex;
  4233. this.watchExpressions.splice(index, 1);
  4234. }
  4235. else
  4236. this.watchExpressions[element.property.watchIndex] = value;
  4237. this.saveExpressions();
  4238. this.update();
  4239. },
  4240.  
  4241. _deleteAllExpressions: function()
  4242. {
  4243. this.watchExpressions = [];
  4244. this.saveExpressions();
  4245. this.update();
  4246. },
  4247.  
  4248. findAddedTreeElement: function()
  4249. {
  4250. var children = this.propertiesTreeOutline.children;
  4251. for (var i = 0; i < children.length; ++i) {
  4252. if (children[i].property.name === WebInspector.WatchExpressionsSection.NewWatchExpression)
  4253. return children[i];
  4254. }
  4255. },
  4256.  
  4257. saveExpressions: function()
  4258. {
  4259. var toSave = [];
  4260. for (var i = 0; i < this.watchExpressions.length; i++)
  4261. if (this.watchExpressions[i])
  4262. toSave.push(this.watchExpressions[i]);
  4263.  
  4264. WebInspector.settings.watchExpressions.set(toSave);
  4265. return toSave.length;
  4266. },
  4267.  
  4268. _mouseMove: function(e)
  4269. {
  4270. if (this.propertiesElement.firstChild)
  4271. this._updateHoveredElement(e.pageY);
  4272. },
  4273.  
  4274. _mouseOut: function()
  4275. {
  4276. if (this._hoveredElement) {
  4277. this._hoveredElement.removeStyleClass("hovered");
  4278. delete this._hoveredElement;
  4279. }
  4280. delete this._lastMouseMovePageY;
  4281. },
  4282.  
  4283. _updateHoveredElement: function(pageY)
  4284. {
  4285. var candidateElement = this.propertiesElement.firstChild;
  4286. while (true) {
  4287. var next = candidateElement.nextSibling;
  4288. while (next && !next.clientHeight)
  4289. next = next.nextSibling;
  4290. if (!next || next.totalOffsetTop() > pageY)
  4291. break;
  4292. candidateElement = next;
  4293. }
  4294.  
  4295. if (this._hoveredElement !== candidateElement) {
  4296. if (this._hoveredElement)
  4297. this._hoveredElement.removeStyleClass("hovered");
  4298. if (candidateElement)
  4299. candidateElement.addStyleClass("hovered");
  4300. this._hoveredElement = candidateElement;
  4301. }
  4302.  
  4303. this._lastMouseMovePageY = pageY;
  4304. },
  4305.  
  4306. _emptyElementContextMenu: function(event)
  4307. {
  4308. var contextMenu = new WebInspector.ContextMenu(event);
  4309. contextMenu.appendItem(WebInspector.UIString("Add watch expression"), this.addNewExpressionAndEdit.bind(this));
  4310. contextMenu.show();
  4311. },
  4312.  
  4313. __proto__: WebInspector.ObjectPropertiesSection.prototype
  4314. }
  4315.  
  4316. WebInspector.WatchExpressionsSection.CompareProperties = function(propertyA, propertyB)
  4317. {
  4318. if (propertyA.watchIndex == propertyB.watchIndex)
  4319. return 0;
  4320. else if (propertyA.watchIndex < propertyB.watchIndex)
  4321. return -1;
  4322. else
  4323. return 1;
  4324. }
  4325.  
  4326.  
  4327. WebInspector.WatchExpressionTreeElement = function(property)
  4328. {
  4329. WebInspector.ObjectPropertyTreeElement.call(this, property);
  4330. }
  4331.  
  4332. WebInspector.WatchExpressionTreeElement.prototype = {
  4333. onexpand: function()
  4334. {
  4335. WebInspector.ObjectPropertyTreeElement.prototype.onexpand.call(this);
  4336. this.treeOutline.section._expandedExpressions[this._expression()] = true;
  4337. },
  4338.  
  4339. oncollapse: function()
  4340. {
  4341. WebInspector.ObjectPropertyTreeElement.prototype.oncollapse.call(this);
  4342. delete this.treeOutline.section._expandedExpressions[this._expression()];
  4343. },
  4344.  
  4345. onattach: function()
  4346. {
  4347. WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
  4348. if (this.treeOutline.section._expandedExpressions[this._expression()])
  4349. this.expanded = true;
  4350. },
  4351.  
  4352. _expression: function()
  4353. {
  4354. return this.property.name;
  4355. },
  4356.  
  4357. update: function()
  4358. {
  4359. WebInspector.ObjectPropertyTreeElement.prototype.update.call(this);
  4360.  
  4361. if (this.property.wasThrown)
  4362. this.valueElement.addStyleClass("watch-expressions-error-level");
  4363.  
  4364. var deleteButton = document.createElement("input");
  4365. deleteButton.type = "button";
  4366. deleteButton.title = WebInspector.UIString("Delete watch expression.");
  4367. deleteButton.addStyleClass("enabled-button");
  4368. deleteButton.addStyleClass("delete-button");
  4369. deleteButton.addEventListener("click", this._deleteButtonClicked.bind(this), false);
  4370. this.listItemElement.addEventListener("contextmenu", this._contextMenu.bind(this), false);
  4371. this.listItemElement.insertBefore(deleteButton, this.listItemElement.firstChild);
  4372. },
  4373.  
  4374.  
  4375. populateContextMenu: function(contextMenu)
  4376. {
  4377. if (!this.isEditing()) {
  4378. contextMenu.appendItem(WebInspector.UIString("Add watch expression"), this.treeOutline.section.addNewExpressionAndEdit.bind(this.treeOutline.section));
  4379. contextMenu.appendItem(WebInspector.UIString("Delete watch expression"), this._deleteButtonClicked.bind(this));
  4380. }
  4381. if (this.treeOutline.section.watchExpressions.length > 1)
  4382. contextMenu.appendItem(WebInspector.UIString("Delete all watch expressions"), this._deleteAllButtonClicked.bind(this));
  4383. },
  4384.  
  4385. _contextMenu: function(event)
  4386. {
  4387. var contextMenu = new WebInspector.ContextMenu(event);
  4388. this.populateContextMenu(contextMenu);
  4389. contextMenu.show();
  4390. },
  4391.  
  4392. _deleteAllButtonClicked: function()
  4393. {
  4394. this.treeOutline.section._deleteAllExpressions();
  4395. },
  4396.  
  4397. _deleteButtonClicked: function()
  4398. {
  4399. this.treeOutline.section.updateExpression(this, null);
  4400. },
  4401.  
  4402. renderPromptAsBlock: function()
  4403. {
  4404. return true;
  4405. },
  4406.  
  4407.  
  4408. elementAndValueToEdit: function(event)
  4409. {
  4410. return [this.nameElement, this.property.name.trim()];
  4411. },
  4412.  
  4413. editingCancelled: function(element, context)
  4414. {
  4415. if (!context.elementToEdit.textContent)
  4416. this.treeOutline.section.updateExpression(this, null);
  4417.  
  4418. WebInspector.ObjectPropertyTreeElement.prototype.editingCancelled.call(this, element, context);
  4419. },
  4420.  
  4421. applyExpression: function(expression, updateInterface)
  4422. {
  4423. expression = expression.trim();
  4424.  
  4425. if (!expression)
  4426. expression = null;
  4427.  
  4428. this.property.name = expression;
  4429. this.treeOutline.section.updateExpression(this, expression);
  4430. },
  4431.  
  4432. __proto__: WebInspector.ObjectPropertyTreeElement.prototype
  4433. }
  4434.  
  4435.  
  4436.  
  4437. WebInspector.WatchedPropertyTreeElement = function(property)
  4438. {
  4439. WebInspector.ObjectPropertyTreeElement.call(this, property);
  4440. }
  4441.  
  4442. WebInspector.WatchedPropertyTreeElement.prototype = {
  4443. onattach: function()
  4444. {
  4445. WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
  4446. if (this.hasChildren && this.propertyPath() in this.treeOutline.section._expandedProperties)
  4447. this.expand();
  4448. },
  4449.  
  4450. onexpand: function()
  4451. {
  4452. WebInspector.ObjectPropertyTreeElement.prototype.onexpand.call(this);
  4453. this.treeOutline.section._expandedProperties[this.propertyPath()] = true;
  4454. },
  4455.  
  4456. oncollapse: function()
  4457. {
  4458. WebInspector.ObjectPropertyTreeElement.prototype.oncollapse.call(this);
  4459. delete this.treeOutline.section._expandedProperties[this.propertyPath()];
  4460. },
  4461.  
  4462. __proto__: WebInspector.ObjectPropertyTreeElement.prototype
  4463. }
  4464. ;
  4465.  
  4466.  
  4467.  
  4468. WebInspector.Worker = function(id, url, shared)
  4469. {
  4470. this.id = id;
  4471. this.url = url;
  4472. this.shared = shared;
  4473. }
  4474.  
  4475.  
  4476. WebInspector.WorkersSidebarPane = function(workerManager)
  4477. {
  4478. WebInspector.SidebarPane.call(this, WebInspector.UIString("Workers"));
  4479.  
  4480. this._enableWorkersCheckbox = new WebInspector.Checkbox(
  4481. WebInspector.UIString("Pause on start"),
  4482. "sidebar-label",
  4483. WebInspector.UIString("Automatically attach to new workers and pause them. Enabling this option will force opening inspector for all new workers."));
  4484. this._enableWorkersCheckbox.element.id = "pause-workers-checkbox";
  4485. this.bodyElement.appendChild(this._enableWorkersCheckbox.element);
  4486. this._enableWorkersCheckbox.addEventListener(this._autoattachToWorkersClicked.bind(this));
  4487. this._enableWorkersCheckbox.checked = false;
  4488.  
  4489. if (Preferences.sharedWorkersDebugNote) {
  4490. var note = this.bodyElement.createChild("div");
  4491. note.id = "shared-workers-list";
  4492. note.addStyleClass("sidebar-label")
  4493. note.textContent = Preferences.sharedWorkersDebugNote;
  4494. }
  4495.  
  4496. var separator = this.bodyElement.createChild("div", "sidebar-separator");
  4497. separator.textContent = WebInspector.UIString("Dedicated worker inspectors");
  4498.  
  4499. this._workerListElement = document.createElement("ol");
  4500. this._workerListElement.tabIndex = 0;
  4501. this._workerListElement.addStyleClass("properties-tree");
  4502. this._workerListElement.addStyleClass("sidebar-label");
  4503. this.bodyElement.appendChild(this._workerListElement);
  4504.  
  4505. this._idToWorkerItem = {};
  4506. this._workerManager = workerManager;
  4507.  
  4508. workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerAdded, this._workerAdded, this);
  4509. workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerRemoved, this._workerRemoved, this);
  4510. workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkersCleared, this._workersCleared, this);
  4511. }
  4512.  
  4513. WebInspector.WorkersSidebarPane.prototype = {
  4514. _workerAdded: function(event)
  4515. {
  4516. this._addWorker(event.data.workerId, event.data.url, event.data.inspectorConnected);
  4517. },
  4518.  
  4519. _workerRemoved: function(event)
  4520. {
  4521. var workerItem = this._idToWorkerItem[event.data];
  4522. delete this._idToWorkerItem[event.data];
  4523. workerItem.parentElement.removeChild(workerItem);
  4524. },
  4525.  
  4526. _workersCleared: function(event)
  4527. {
  4528. this._idToWorkerItem = {};
  4529. this._workerListElement.removeChildren();
  4530. },
  4531.  
  4532. _addWorker: function(workerId, url, inspectorConnected)
  4533. {
  4534. var item = this._workerListElement.createChild("div", "dedicated-worker-item");
  4535. var link = item.createChild("a");
  4536. link.textContent = url;
  4537. link.href = "#";
  4538. link.target = "_blank";
  4539. link.addEventListener("click", this._workerItemClicked.bind(this, workerId), true);
  4540. this._idToWorkerItem[workerId] = item;
  4541. },
  4542.  
  4543. _workerItemClicked: function(workerId, event)
  4544. {
  4545. event.preventDefault();
  4546. this._workerManager.openWorkerInspector(workerId);
  4547. },
  4548.  
  4549. _autoattachToWorkersClicked: function(event)
  4550. {
  4551. WorkerAgent.setAutoconnectToWorkers(this._enableWorkersCheckbox.checked);
  4552. },
  4553.  
  4554. __proto__: WebInspector.SidebarPane.prototype
  4555. }
  4556. ;
  4557.  
  4558.  
  4559. WebInspector.ScriptsPanel = function(workspaceForTest)
  4560. {
  4561. WebInspector.Panel.call(this, "scripts");
  4562. this.registerRequiredCSS("scriptsPanel.css");
  4563.  
  4564. WebInspector.settings.navigatorWasOnceHidden = WebInspector.settings.createSetting("navigatorWasOnceHidden", false);
  4565. WebInspector.settings.debuggerSidebarHidden = WebInspector.settings.createSetting("debuggerSidebarHidden", false);
  4566.  
  4567. this._workspace = workspaceForTest || WebInspector.workspace;
  4568.  
  4569. function viewGetter()
  4570. {
  4571. return this.visibleView;
  4572. }
  4573. WebInspector.GoToLineDialog.install(this, viewGetter.bind(this));
  4574.  
  4575. var helpSection = WebInspector.shortcutsScreen.section(WebInspector.UIString("Sources Panel"));
  4576. this.debugToolbar = this._createDebugToolbar(helpSection);
  4577.  
  4578. const initialDebugSidebarWidth = 225;
  4579. const minimumDebugSidebarWidthPercent = 50;
  4580. this.createSidebarView(this.element, WebInspector.SidebarView.SidebarPosition.Right, initialDebugSidebarWidth);
  4581. this.splitView.element.id = "scripts-split-view";
  4582. this.splitView.setMinimumSidebarWidth(Preferences.minScriptsSidebarWidth);
  4583. this.splitView.setMinimumMainWidthPercent(minimumDebugSidebarWidthPercent);
  4584.  
  4585. this.sidebarElement.appendChild(this.debugToolbar);
  4586.  
  4587. this.debugSidebarResizeWidgetElement = document.createElement("div");
  4588. this.debugSidebarResizeWidgetElement.id = "scripts-debug-sidebar-resizer-widget";
  4589. this.splitView.installResizer(this.debugSidebarResizeWidgetElement);
  4590.  
  4591.  
  4592. const initialNavigatorWidth = 225;
  4593. const minimumViewsContainerWidthPercent = 50;
  4594. this.editorView = new WebInspector.SidebarView(WebInspector.SidebarView.SidebarPosition.Left, "scriptsPanelNavigatorSidebarWidth", initialNavigatorWidth);
  4595. this.editorView.element.tabIndex = 0;
  4596.  
  4597. this.editorView.setMinimumSidebarWidth(Preferences.minScriptsSidebarWidth);
  4598. this.editorView.setMinimumMainWidthPercent(minimumViewsContainerWidthPercent);
  4599. this.editorView.show(this.splitView.mainElement);
  4600.  
  4601. this._navigator = new WebInspector.ScriptsNavigator();
  4602. this._navigator.view.show(this.editorView.sidebarElement);
  4603.  
  4604. this._editorContainer = new WebInspector.TabbedEditorContainer(this, "previouslyViewedFiles");
  4605. this._editorContainer.show(this.editorView.mainElement);
  4606.  
  4607. this._navigatorController = new WebInspector.NavigatorOverlayController(this.editorView, this._navigator.view, this._editorContainer.view);
  4608.  
  4609. this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.ScriptSelected, this._scriptSelected, this);
  4610. this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.SnippetCreationRequested, this._snippetCreationRequested, this);
  4611. this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.ItemRenamingRequested, this._itemRenamingRequested, this);
  4612. this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.FileRenamed, this._fileRenamed, this);
  4613.  
  4614. this._editorContainer.addEventListener(WebInspector.TabbedEditorContainer.Events.EditorSelected, this._editorSelected, this);
  4615. this._editorContainer.addEventListener(WebInspector.TabbedEditorContainer.Events.EditorClosed, this._editorClosed, this);
  4616.  
  4617. this.splitView.mainElement.appendChild(this.debugSidebarResizeWidgetElement);
  4618.  
  4619. this.sidebarPanes = {};
  4620. this.sidebarPanes.watchExpressions = new WebInspector.WatchExpressionsSidebarPane();
  4621. this.sidebarPanes.callstack = new WebInspector.CallStackSidebarPane();
  4622. this.sidebarPanes.scopechain = new WebInspector.ScopeChainSidebarPane();
  4623. this.sidebarPanes.jsBreakpoints = new WebInspector.JavaScriptBreakpointsSidebarPane(WebInspector.breakpointManager, this._showSourceLine.bind(this));
  4624. this.sidebarPanes.domBreakpoints = WebInspector.domBreakpointsSidebarPane;
  4625. this.sidebarPanes.xhrBreakpoints = new WebInspector.XHRBreakpointsSidebarPane();
  4626. this.sidebarPanes.eventListenerBreakpoints = new WebInspector.EventListenerBreakpointsSidebarPane();
  4627.  
  4628. if (InspectorFrontendHost.canInspectWorkers() && !WebInspector.WorkerManager.isWorkerFrontend()) {
  4629. WorkerAgent.enable();
  4630. this.sidebarPanes.workerList = new WebInspector.WorkersSidebarPane(WebInspector.workerManager);
  4631. }
  4632.  
  4633. this._debugSidebarContentsElement = document.createElement("div");
  4634. this._debugSidebarContentsElement.id = "scripts-debug-sidebar-contents";
  4635. this.sidebarElement.appendChild(this._debugSidebarContentsElement);
  4636.  
  4637. for (var pane in this.sidebarPanes)
  4638. this._debugSidebarContentsElement.appendChild(this.sidebarPanes[pane].element);
  4639.  
  4640. this.sidebarPanes.callstack.expanded = true;
  4641.  
  4642. this.sidebarPanes.scopechain.expanded = true;
  4643. this.sidebarPanes.jsBreakpoints.expanded = true;
  4644.  
  4645. this.sidebarPanes.callstack.registerShortcuts(helpSection, this.registerShortcut.bind(this));
  4646. var evaluateInConsoleShortcut = WebInspector.KeyboardShortcut.makeDescriptor("e", WebInspector.KeyboardShortcut.Modifiers.Shift | WebInspector.KeyboardShortcut.Modifiers.Ctrl);
  4647. helpSection.addKey(evaluateInConsoleShortcut.name, WebInspector.UIString("Evaluate selection in console"));
  4648. this.registerShortcut(evaluateInConsoleShortcut.key, this._evaluateSelectionInConsole.bind(this));
  4649.  
  4650. var outlineShortcut = WebInspector.KeyboardShortcut.makeDescriptor("o", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta | WebInspector.KeyboardShortcut.Modifiers.Shift);
  4651. helpSection.addKey(outlineShortcut.name, WebInspector.UIString("Go to member"));
  4652. this.registerShortcut(outlineShortcut.key, this._showOutlineDialog.bind(this));
  4653.  
  4654. var createBreakpointShortcut = WebInspector.KeyboardShortcut.makeDescriptor("b", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta);
  4655. helpSection.addKey(createBreakpointShortcut.name, WebInspector.UIString("Toggle breakpoint"));
  4656. this.registerShortcut(createBreakpointShortcut.key, this._toggleBreakpoint.bind(this));
  4657.  
  4658. var panelEnablerHeading = WebInspector.UIString("You need to enable debugging before you can use the Scripts panel.");
  4659. var panelEnablerDisclaimer = WebInspector.UIString("Enabling debugging will make scripts run slower.");
  4660. var panelEnablerButton = WebInspector.UIString("Enable Debugging");
  4661.  
  4662. this.panelEnablerView = new WebInspector.PanelEnablerView("scripts", panelEnablerHeading, panelEnablerDisclaimer, panelEnablerButton);
  4663. this.panelEnablerView.addEventListener("enable clicked", this._enableDebugging, this);
  4664.  
  4665. this.enableToggleButton = new WebInspector.StatusBarButton("", "enable-toggle-status-bar-item");
  4666. this.enableToggleButton.addEventListener("click", this._toggleDebugging, this);
  4667. if (!Capabilities.debuggerCausesRecompilation)
  4668. this.enableToggleButton.element.addStyleClass("hidden");
  4669.  
  4670. this._pauseOnExceptionButton = new WebInspector.StatusBarButton("", "scripts-pause-on-exceptions-status-bar-item", 3);
  4671. this._pauseOnExceptionButton.addEventListener("click", this._togglePauseOnExceptions, this);
  4672.  
  4673. this._toggleFormatSourceButton = new WebInspector.StatusBarButton(WebInspector.UIString("Pretty print"), "scripts-toggle-pretty-print-status-bar-item");
  4674. this._toggleFormatSourceButton.toggled = false;
  4675. this._toggleFormatSourceButton.addEventListener("click", this._toggleFormatSource, this);
  4676.  
  4677. this._scriptViewStatusBarItemsContainer = document.createElement("div");
  4678. this._scriptViewStatusBarItemsContainer.style.display = "inline-block";
  4679.  
  4680. this._installDebuggerSidebarController();
  4681.  
  4682. this._sourceFramesByUISourceCode = new Map();
  4683. this._updateDebuggerButtons();
  4684. this._pauseOnExceptionStateChanged();
  4685. if (WebInspector.debuggerModel.isPaused())
  4686. this._debuggerPaused();
  4687.  
  4688. WebInspector.settings.pauseOnExceptionStateString.addChangeListener(this._pauseOnExceptionStateChanged, this);
  4689. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerWasEnabled, this._debuggerWasEnabled, this);
  4690. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerWasDisabled, this._debuggerWasDisabled, this);
  4691. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
  4692. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
  4693. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.CallFrameSelected, this._callFrameSelected, this);
  4694. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ConsoleCommandEvaluatedInSelectedCallFrame, this._consoleCommandEvaluatedInSelectedCallFrame, this);
  4695. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ExecutionLineChanged, this._executionLineChanged, this);
  4696. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointsActiveStateChanged, this._breakpointsActiveStateChanged, this);
  4697.  
  4698. WebInspector.startBatchUpdate();
  4699. var uiSourceCodes = this._workspace.uiSourceCodes();
  4700. for (var i = 0; i < uiSourceCodes.length; ++i)
  4701. this._addUISourceCode(uiSourceCodes[i]);
  4702. WebInspector.endBatchUpdate();
  4703.  
  4704. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAdded, this);
  4705. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, this._uiSourceCodeRemoved, this);
  4706. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeRemoved, this._uiSourceCodeRemoved, this);
  4707. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset.bind(this), this);
  4708.  
  4709. WebInspector.advancedSearchController.registerSearchScope(new WebInspector.ScriptsSearchScope(this._workspace));
  4710. }
  4711.  
  4712. WebInspector.ScriptsPanel.prototype = {
  4713. get statusBarItems()
  4714. {
  4715. return [this.enableToggleButton.element, this._pauseOnExceptionButton.element, this._toggleFormatSourceButton.element, this._scriptViewStatusBarItemsContainer];
  4716. },
  4717.  
  4718. defaultFocusedElement: function()
  4719. {
  4720. return this._navigator.view.defaultFocusedElement();
  4721. },
  4722.  
  4723. get paused()
  4724. {
  4725. return this._paused;
  4726. },
  4727.  
  4728. wasShown: function()
  4729. {
  4730. WebInspector.Panel.prototype.wasShown.call(this);
  4731. this._debugSidebarContentsElement.insertBefore(this.sidebarPanes.domBreakpoints.element, this.sidebarPanes.xhrBreakpoints.element);
  4732. this.sidebarPanes.watchExpressions.show();
  4733.  
  4734. this._navigatorController.wasShown();
  4735. },
  4736.  
  4737. willHide: function()
  4738. {
  4739. WebInspector.Panel.prototype.willHide.call(this);
  4740. WebInspector.closeViewInDrawer();
  4741. },
  4742.  
  4743.  
  4744. _uiSourceCodeAdded: function(event)
  4745. {
  4746. var uiSourceCode =   (event.data);
  4747. this._addUISourceCode(uiSourceCode);
  4748. },
  4749.  
  4750.  
  4751. _addUISourceCode: function(uiSourceCode)
  4752. {
  4753. if (this._toggleFormatSourceButton.toggled)
  4754. uiSourceCode.setFormatted(true);
  4755.  
  4756. this._navigator.addUISourceCode(uiSourceCode);
  4757. this._editorContainer.addUISourceCode(uiSourceCode);
  4758. },
  4759.  
  4760. _uiSourceCodeRemoved: function(event)
  4761. {
  4762. var uiSourceCode =   (event.data);
  4763. this._editorContainer.removeUISourceCode(uiSourceCode);
  4764. this._navigator.removeUISourceCode(uiSourceCode);
  4765. this._removeSourceFrame(uiSourceCode);
  4766. },
  4767.  
  4768. _consoleCommandEvaluatedInSelectedCallFrame: function(event)
  4769. {
  4770. this.sidebarPanes.scopechain.update(WebInspector.debuggerModel.selectedCallFrame());
  4771. },
  4772.  
  4773. _debuggerPaused: function()
  4774. {
  4775. var details = WebInspector.debuggerModel.debuggerPausedDetails();
  4776.  
  4777. this._paused = true;
  4778. this._waitingToPause = false;
  4779. this._stepping = false;
  4780.  
  4781. this._updateDebuggerButtons();
  4782.  
  4783. WebInspector.inspectorView.setCurrentPanel(this);
  4784. this.sidebarPanes.callstack.update(details.callFrames);
  4785.  
  4786. if (details.reason === WebInspector.DebuggerModel.BreakReason.DOM) {
  4787. this.sidebarPanes.domBreakpoints.highlightBreakpoint(details.auxData);
  4788. function didCreateBreakpointHitStatusMessage(element)
  4789. {
  4790. this.sidebarPanes.callstack.setStatus(element);
  4791. }
  4792. this.sidebarPanes.domBreakpoints.createBreakpointHitStatusMessage(details.auxData, didCreateBreakpointHitStatusMessage.bind(this));
  4793. } else if (details.reason === WebInspector.DebuggerModel.BreakReason.EventListener) {
  4794. var eventName = details.auxData.eventName;
  4795. this.sidebarPanes.eventListenerBreakpoints.highlightBreakpoint(details.auxData.eventName);
  4796. var eventNameForUI = WebInspector.EventListenerBreakpointsSidebarPane.eventNameForUI(eventName);
  4797. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a \"%s\" Event Listener.", eventNameForUI));
  4798. } else if (details.reason === WebInspector.DebuggerModel.BreakReason.XHR) {
  4799. this.sidebarPanes.xhrBreakpoints.highlightBreakpoint(details.auxData["breakpointURL"]);
  4800. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a XMLHttpRequest."));
  4801. } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Exception)
  4802. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on exception: '%s'.", details.auxData.description));
  4803. else if (details.reason === WebInspector.DebuggerModel.BreakReason.Assert)
  4804. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on assertion."));
  4805. else if (details.reason === WebInspector.DebuggerModel.BreakReason.CSPViolation)
  4806. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a script blocked due to Content Security Policy directive: \"%s\".", details.auxData["directiveText"]));
  4807. else {
  4808. function didGetUILocation(uiLocation)
  4809. {
  4810. var breakpoint = WebInspector.breakpointManager.findBreakpoint(uiLocation.uiSourceCode, uiLocation.lineNumber);
  4811. if (!breakpoint)
  4812. return;
  4813. this.sidebarPanes.jsBreakpoints.highlightBreakpoint(breakpoint);
  4814. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a JavaScript breakpoint."));
  4815. }
  4816. details.callFrames[0].createLiveLocation(didGetUILocation.bind(this));
  4817. }
  4818.  
  4819. this._showDebuggerSidebar();
  4820. this._toggleDebuggerSidebarButton.disabled = true;
  4821. window.focus();
  4822. InspectorFrontendHost.bringToFront();
  4823. },
  4824.  
  4825. _debuggerResumed: function()
  4826. {
  4827. this._paused = false;
  4828. this._waitingToPause = false;
  4829. this._stepping = false;
  4830.  
  4831. this._clearInterface();
  4832. this._toggleDebuggerSidebarButton.disabled = false;
  4833. },
  4834.  
  4835. _debuggerWasEnabled: function()
  4836. {
  4837. this._updateDebuggerButtons();
  4838. },
  4839.  
  4840. _debuggerWasDisabled: function()
  4841. {
  4842. this._reset();
  4843. },
  4844.  
  4845. _reset: function()
  4846. {
  4847. delete this.currentQuery;
  4848. this.searchCanceled();
  4849.  
  4850. this._debuggerResumed();
  4851.  
  4852. delete this._currentUISourceCode;
  4853. this._navigator.reset();
  4854. this._editorContainer.reset();
  4855. this._updateScriptViewStatusBarItems();
  4856. this.sidebarPanes.jsBreakpoints.reset();
  4857. this.sidebarPanes.watchExpressions.reset();
  4858.  
  4859. var uiSourceCodes = this._workspace.uiSourceCodes();
  4860. for (var i = 0; i < uiSourceCodes.length; ++i)
  4861. this._removeSourceFrame(uiSourceCodes[i]);
  4862. },
  4863.  
  4864. get visibleView()
  4865. {
  4866. return this._editorContainer.visibleView;
  4867. },
  4868.  
  4869. _updateScriptViewStatusBarItems: function()
  4870. {
  4871. this._scriptViewStatusBarItemsContainer.removeChildren();
  4872.  
  4873. var sourceFrame = this.visibleView;
  4874. if (sourceFrame) {
  4875. var statusBarItems = sourceFrame.statusBarItems() || [];
  4876. for (var i = 0; i < statusBarItems.length; ++i)
  4877. this._scriptViewStatusBarItemsContainer.appendChild(statusBarItems[i]);
  4878. }
  4879. },
  4880.  
  4881. canShowAnchorLocation: function(anchor)
  4882. {
  4883. if (WebInspector.debuggerModel.debuggerEnabled() && anchor.uiSourceCode)
  4884. return true;
  4885. var uiSourceCodes = this._workspace.uiSourceCodes();
  4886. for (var i = 0; i < uiSourceCodes.length; ++i) {
  4887. if (uiSourceCodes[i].url === anchor.href) {
  4888. anchor.uiSourceCode = uiSourceCodes[i];
  4889. return true;
  4890. }
  4891. }
  4892. return false;
  4893. },
  4894.  
  4895. showAnchorLocation: function(anchor)
  4896. {
  4897. this._showSourceLine(anchor.uiSourceCode, anchor.lineNumber);
  4898. },
  4899.  
  4900.  
  4901. showUISourceCode: function(uiSourceCode, lineNumber)
  4902. {
  4903. this._showSourceLine(uiSourceCode, lineNumber);
  4904. },
  4905.  
  4906.  
  4907. _showSourceLine: function(uiSourceCode, lineNumber)
  4908. {
  4909. var sourceFrame = this._showFile(uiSourceCode);
  4910. if (typeof lineNumber === "number")
  4911. sourceFrame.highlightLine(lineNumber);
  4912. sourceFrame.focus();
  4913. },
  4914.  
  4915.  
  4916. _showFile: function(uiSourceCode)
  4917. {
  4918. var sourceFrame = this._getOrCreateSourceFrame(uiSourceCode);
  4919. if (this._currentUISourceCode === uiSourceCode)
  4920. return sourceFrame;
  4921. this._currentUISourceCode = uiSourceCode;
  4922.  
  4923. if (this._navigator.isScriptSourceAdded(uiSourceCode))
  4924. this._navigator.revealUISourceCode(uiSourceCode);
  4925. this._editorContainer.showFile(uiSourceCode);
  4926. this._updateScriptViewStatusBarItems();
  4927.  
  4928. return sourceFrame;
  4929. },
  4930.  
  4931.  
  4932. _createSourceFrame: function(uiSourceCode)
  4933. {
  4934. var sourceFrame;
  4935. switch (uiSourceCode.contentType()) {
  4936. case WebInspector.resourceTypes.Script:
  4937. if (uiSourceCode.isSnippet && !uiSourceCode.isTemporary)
  4938. sourceFrame = new WebInspector.SnippetJavaScriptSourceFrame(this, uiSourceCode);
  4939. else
  4940. sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceCode);
  4941. break;
  4942. case WebInspector.resourceTypes.Document:
  4943. sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceCode);
  4944. break;
  4945. case WebInspector.resourceTypes.Stylesheet:
  4946. default:
  4947. sourceFrame = new WebInspector.UISourceCodeFrame(uiSourceCode);
  4948. break;
  4949. }
  4950. this._sourceFramesByUISourceCode.put(uiSourceCode, sourceFrame);
  4951. return sourceFrame;
  4952. },
  4953.  
  4954.  
  4955. _getOrCreateSourceFrame: function(uiSourceCode)
  4956. {
  4957. return this._sourceFramesByUISourceCode.get(uiSourceCode) || this._createSourceFrame(uiSourceCode);
  4958. },
  4959.  
  4960.  
  4961. viewForFile: function(uiSourceCode)
  4962. {
  4963. return this._getOrCreateSourceFrame(uiSourceCode);
  4964. },
  4965.  
  4966.  
  4967. _removeSourceFrame: function(uiSourceCode)
  4968. {
  4969. var sourceFrame = this._sourceFramesByUISourceCode.get(uiSourceCode);
  4970. if (!sourceFrame)
  4971. return;
  4972. this._sourceFramesByUISourceCode.remove(uiSourceCode);
  4973. sourceFrame.detach();
  4974. },
  4975.  
  4976. _clearCurrentExecutionLine: function()
  4977. {
  4978. if (this._executionSourceFrame)
  4979. this._executionSourceFrame.clearExecutionLine();
  4980. delete this._executionSourceFrame;
  4981. },
  4982.  
  4983. _executionLineChanged: function(event)
  4984. {
  4985. var uiLocation = event.data;
  4986.  
  4987. this._clearCurrentExecutionLine();
  4988. if (!uiLocation)
  4989. return;
  4990. var sourceFrame = this._getOrCreateSourceFrame(uiLocation.uiSourceCode);
  4991. sourceFrame.setExecutionLine(uiLocation.lineNumber);
  4992. this._executionSourceFrame = sourceFrame;
  4993. },
  4994.  
  4995. _revealExecutionLine: function(uiLocation)
  4996. {
  4997. var uiSourceCode = uiLocation.uiSourceCode;
  4998.  
  4999. if (uiSourceCode.isTemporary) {
  5000. if (this._currentUISourceCode && this._currentUISourceCode.scriptFile() && this._currentUISourceCode.scriptFile().isDivergingFromVM())
  5001. return;
  5002. this._editorContainer.addUISourceCode(uiSourceCode);
  5003. if (uiSourceCode.formatted() !== this._toggleFormatSourceButton.toggled)
  5004. uiSourceCode.setFormatted(this._toggleFormatSourceButton.toggled);
  5005. }
  5006. var sourceFrame = this._showFile(uiSourceCode);
  5007. sourceFrame.revealLine(uiLocation.lineNumber);
  5008. sourceFrame.focus();
  5009. },
  5010.  
  5011. _callFrameSelected: function(event)
  5012. {
  5013. var callFrame = event.data;
  5014.  
  5015. if (!callFrame)
  5016. return;
  5017.  
  5018. this.sidebarPanes.scopechain.update(callFrame);
  5019. this.sidebarPanes.watchExpressions.refreshExpressions();
  5020. this.sidebarPanes.callstack.setSelectedCallFrame(callFrame);
  5021. callFrame.createLiveLocation(this._revealExecutionLine.bind(this));
  5022. },
  5023.  
  5024. _editorClosed: function(event)
  5025. {
  5026. this._navigatorController.hideNavigatorOverlay();
  5027. var uiSourceCode =   (event.data);
  5028.  
  5029. if (this._currentUISourceCode === uiSourceCode)
  5030. delete this._currentUISourceCode;
  5031.  
  5032.  
  5033. this._updateScriptViewStatusBarItems();
  5034. WebInspector.searchController.resetSearch();
  5035. },
  5036.  
  5037. _editorSelected: function(event)
  5038. {
  5039. var uiSourceCode =   (event.data);
  5040. var sourceFrame = this._showFile(uiSourceCode);
  5041. this._navigatorController.hideNavigatorOverlay();
  5042. sourceFrame.focus();
  5043. WebInspector.searchController.resetSearch();
  5044. },
  5045.  
  5046. _scriptSelected: function(event)
  5047. {
  5048. var uiSourceCode =   (event.data.uiSourceCode);
  5049. var sourceFrame = this._showFile(uiSourceCode);
  5050. this._navigatorController.hideNavigatorOverlay();
  5051. if (sourceFrame && event.data.focusSource)
  5052. sourceFrame.focus();
  5053. },
  5054.  
  5055. _pauseOnExceptionStateChanged: function()
  5056. {
  5057. var pauseOnExceptionsState = WebInspector.settings.pauseOnExceptionStateString.get();
  5058. switch (pauseOnExceptionsState) {
  5059. case WebInspector.DebuggerModel.PauseOnExceptionsState.DontPauseOnExceptions:
  5060. this._pauseOnExceptionButton.title = WebInspector.UIString("Don't pause on exceptions.\nClick to Pause on all exceptions.");
  5061. break;
  5062. case WebInspector.DebuggerModel.PauseOnExceptionsState.PauseOnAllExceptions:
  5063. this._pauseOnExceptionButton.title = WebInspector.UIString("Pause on all exceptions.\nClick to Pause on uncaught exceptions.");
  5064. break;
  5065. case WebInspector.DebuggerModel.PauseOnExceptionsState.PauseOnUncaughtExceptions:
  5066. this._pauseOnExceptionButton.title = WebInspector.UIString("Pause on uncaught exceptions.\nClick to Not pause on exceptions.");
  5067. break;
  5068. }
  5069. this._pauseOnExceptionButton.state = pauseOnExceptionsState;
  5070. },
  5071.  
  5072. _updateDebuggerButtons: function()
  5073. {
  5074. if (WebInspector.debuggerModel.debuggerEnabled()) {
  5075. this.enableToggleButton.title = WebInspector.UIString("Debugging enabled. Click to disable.");
  5076. this.enableToggleButton.toggled = true;
  5077. this._pauseOnExceptionButton.visible = true;
  5078. this.panelEnablerView.detach();
  5079. } else {
  5080. this.enableToggleButton.title = WebInspector.UIString("Debugging disabled. Click to enable.");
  5081. this.enableToggleButton.toggled = false;
  5082. this._pauseOnExceptionButton.visible = false;
  5083. this.panelEnablerView.show(this.element);
  5084. }
  5085.  
  5086. if (this._paused) {
  5087. this._updateButtonTitle(this.pauseButton, WebInspector.UIString("Resume script execution (%s)."))
  5088. this.pauseButton.addStyleClass("paused");
  5089.  
  5090. this.pauseButton.disabled = false;
  5091. this.stepOverButton.disabled = false;
  5092. this.stepIntoButton.disabled = false;
  5093. this.stepOutButton.disabled = false;
  5094.  
  5095. this.debuggerStatusElement.textContent = WebInspector.UIString("Paused");
  5096. } else {
  5097. this._updateButtonTitle(this.pauseButton, WebInspector.UIString("Pause script execution (%s)."))
  5098. this.pauseButton.removeStyleClass("paused");
  5099.  
  5100. this.pauseButton.disabled = this._waitingToPause;
  5101. this.stepOverButton.disabled = true;
  5102. this.stepIntoButton.disabled = true;
  5103. this.stepOutButton.disabled = true;
  5104.  
  5105. if (this._waitingToPause)
  5106. this.debuggerStatusElement.textContent = WebInspector.UIString("Pausing");
  5107. else if (this._stepping)
  5108. this.debuggerStatusElement.textContent = WebInspector.UIString("Stepping");
  5109. else
  5110. this.debuggerStatusElement.textContent = "";
  5111. }
  5112. },
  5113.  
  5114. _clearInterface: function()
  5115. {
  5116. this.sidebarPanes.callstack.update(null);
  5117. this.sidebarPanes.scopechain.update(null);
  5118. this.sidebarPanes.jsBreakpoints.clearBreakpointHighlight();
  5119. this.sidebarPanes.domBreakpoints.clearBreakpointHighlight();
  5120. this.sidebarPanes.eventListenerBreakpoints.clearBreakpointHighlight();
  5121. this.sidebarPanes.xhrBreakpoints.clearBreakpointHighlight();
  5122.  
  5123. this._clearCurrentExecutionLine();
  5124. this._updateDebuggerButtons();
  5125. },
  5126.  
  5127. _enableDebugging: function()
  5128. {
  5129. this._toggleDebugging(this.panelEnablerView.alwaysEnabled);
  5130. },
  5131.  
  5132. _toggleDebugging: function(optionalAlways)
  5133. {
  5134. this._paused = false;
  5135. this._waitingToPause = false;
  5136. this._stepping = false;
  5137.  
  5138. if (WebInspector.debuggerModel.debuggerEnabled()) {
  5139. WebInspector.settings.debuggerEnabled.set(false);
  5140. WebInspector.debuggerModel.disableDebugger();
  5141. } else {
  5142. WebInspector.settings.debuggerEnabled.set(!!optionalAlways);
  5143. WebInspector.debuggerModel.enableDebugger();
  5144. }
  5145. },
  5146.  
  5147. _togglePauseOnExceptions: function()
  5148. {
  5149. var nextStateMap = {};
  5150. var stateEnum = WebInspector.DebuggerModel.PauseOnExceptionsState;
  5151. nextStateMap[stateEnum.DontPauseOnExceptions] = stateEnum.PauseOnAllExceptions;
  5152. nextStateMap[stateEnum.PauseOnAllExceptions] = stateEnum.PauseOnUncaughtExceptions;
  5153. nextStateMap[stateEnum.PauseOnUncaughtExceptions] = stateEnum.DontPauseOnExceptions;
  5154. WebInspector.settings.pauseOnExceptionStateString.set(nextStateMap[this._pauseOnExceptionButton.state]);
  5155. },
  5156.  
  5157. _togglePause: function()
  5158. {
  5159. if (this._paused) {
  5160. this._paused = false;
  5161. this._waitingToPause = false;
  5162. DebuggerAgent.resume();
  5163. } else {
  5164. this._stepping = false;
  5165. this._waitingToPause = true;
  5166. DebuggerAgent.pause();
  5167. }
  5168.  
  5169. this._clearInterface();
  5170. },
  5171.  
  5172. _stepOverClicked: function()
  5173. {
  5174. if (!this._paused)
  5175. return;
  5176.  
  5177. this._paused = false;
  5178. this._stepping = true;
  5179.  
  5180. this._clearInterface();
  5181.  
  5182. DebuggerAgent.stepOver();
  5183. },
  5184.  
  5185. _stepIntoClicked: function()
  5186. {
  5187. if (!this._paused)
  5188. return;
  5189.  
  5190. this._paused = false;
  5191. this._stepping = true;
  5192.  
  5193. this._clearInterface();
  5194.  
  5195. DebuggerAgent.stepInto();
  5196. },
  5197.  
  5198. _stepOutClicked: function()
  5199. {
  5200. if (!this._paused)
  5201. return;
  5202.  
  5203. this._paused = false;
  5204. this._stepping = true;
  5205.  
  5206. this._clearInterface();
  5207.  
  5208. DebuggerAgent.stepOut();
  5209. },
  5210.  
  5211. _toggleBreakpointsClicked: function(event)
  5212. {
  5213. WebInspector.debuggerModel.setBreakpointsActive(!WebInspector.debuggerModel.breakpointsActive());
  5214. },
  5215.  
  5216. _breakpointsActiveStateChanged: function(event)
  5217. {
  5218. var active = event.data;
  5219. this._toggleBreakpointsButton.toggled = active;
  5220. if (active) {
  5221. this._toggleBreakpointsButton.title = WebInspector.UIString("Deactivate breakpoints.");
  5222. WebInspector.inspectorView.element.removeStyleClass("breakpoints-deactivated");
  5223. this.sidebarPanes.jsBreakpoints.listElement.removeStyleClass("breakpoints-list-deactivated");
  5224. } else {
  5225. this._toggleBreakpointsButton.title = WebInspector.UIString("Activate breakpoints.");
  5226. WebInspector.inspectorView.element.addStyleClass("breakpoints-deactivated");
  5227. this.sidebarPanes.jsBreakpoints.listElement.addStyleClass("breakpoints-list-deactivated");
  5228. }
  5229. },
  5230.  
  5231. _evaluateSelectionInConsole: function()
  5232. {
  5233. var selection = window.getSelection();
  5234. if (selection.type === "Range" && !selection.isCollapsed)
  5235. WebInspector.evaluateInConsole(selection.toString());
  5236. },
  5237.  
  5238. _createDebugToolbar: function(section)
  5239. {
  5240. var debugToolbar = document.createElement("div");
  5241. debugToolbar.className = "status-bar";
  5242. debugToolbar.id = "scripts-debug-toolbar";
  5243.  
  5244. var title, handler, shortcuts;
  5245. var platformSpecificModifier = WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta;
  5246.  
  5247.  
  5248. handler = this._togglePause.bind(this);
  5249. shortcuts = [];
  5250. shortcuts.push(WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.F8));
  5251. shortcuts.push(WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Slash, platformSpecificModifier));
  5252. this.pauseButton = this._createButtonAndRegisterShortcuts(section, "scripts-pause", "", handler, shortcuts, WebInspector.UIString("Pause/Continue"));
  5253. debugToolbar.appendChild(this.pauseButton);
  5254.  
  5255.  
  5256. title = WebInspector.UIString("Step over next function call (%s).");
  5257. handler = this._stepOverClicked.bind(this);
  5258. shortcuts = [];
  5259. shortcuts.push(WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.F10));
  5260. shortcuts.push(WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.SingleQuote, platformSpecificModifier));
  5261. this.stepOverButton = this._createButtonAndRegisterShortcuts(section, "scripts-step-over", title, handler, shortcuts, WebInspector.UIString("Step over"));
  5262. debugToolbar.appendChild(this.stepOverButton);
  5263.  
  5264.  
  5265. title = WebInspector.UIString("Step into next function call (%s).");
  5266. handler = this._stepIntoClicked.bind(this);
  5267. shortcuts = [];
  5268. shortcuts.push(WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.F11));
  5269. shortcuts.push(WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Semicolon, platformSpecificModifier));
  5270. this.stepIntoButton = this._createButtonAndRegisterShortcuts(section, "scripts-step-into", title, handler, shortcuts, WebInspector.UIString("Step into"));
  5271. debugToolbar.appendChild(this.stepIntoButton);
  5272.  
  5273.  
  5274. title = WebInspector.UIString("Step out of current function (%s).");
  5275. handler = this._stepOutClicked.bind(this);
  5276. shortcuts = [];
  5277. shortcuts.push(WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.F11, WebInspector.KeyboardShortcut.Modifiers.Shift));
  5278. shortcuts.push(WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Semicolon, WebInspector.KeyboardShortcut.Modifiers.Shift | platformSpecificModifier));
  5279. this.stepOutButton = this._createButtonAndRegisterShortcuts(section, "scripts-step-out", title, handler, shortcuts, WebInspector.UIString("Step out"));
  5280. debugToolbar.appendChild(this.stepOutButton);
  5281.  
  5282. this._toggleBreakpointsButton = new WebInspector.StatusBarButton(WebInspector.UIString("Deactivate breakpoints."), "toggle-breakpoints");
  5283. this._toggleBreakpointsButton.toggled = true;
  5284. this._toggleBreakpointsButton.addEventListener("click", this._toggleBreakpointsClicked, this);
  5285. debugToolbar.appendChild(this._toggleBreakpointsButton.element);
  5286.  
  5287. this.debuggerStatusElement = document.createElement("div");
  5288. this.debuggerStatusElement.id = "scripts-debugger-status";
  5289. debugToolbar.appendChild(this.debuggerStatusElement);
  5290.  
  5291. return debugToolbar;
  5292. },
  5293.  
  5294. _updateButtonTitle: function(button, buttonTitle)
  5295. {
  5296. button.buttonTitle = buttonTitle;
  5297. var hasShortcuts = button.shortcuts && button.shortcuts.length;
  5298. if (hasShortcuts)
  5299. button.title = String.vsprintf(buttonTitle, [button.shortcuts[0].name]);
  5300. else
  5301. button.title = buttonTitle;
  5302. },
  5303.  
  5304. _createButtonAndRegisterShortcuts: function(section, buttonId, buttonTitle, handler, shortcuts, shortcutDescription)
  5305. {
  5306. var button = document.createElement("button");
  5307. button.className = "status-bar-item";
  5308. button.id = buttonId;
  5309. button.shortcuts = shortcuts;
  5310. this._updateButtonTitle(button, buttonTitle);
  5311. button.disabled = true;
  5312. button.appendChild(document.createElement("img"));
  5313. button.addEventListener("click", handler, false);
  5314.  
  5315. var shortcutNames = [];
  5316. for (var i = 0; i < shortcuts.length; ++i) {
  5317. this.registerShortcut(shortcuts[i].key, handler);
  5318. shortcutNames.push(shortcuts[i].name);
  5319. }
  5320. section.addAlternateKeys(shortcutNames, shortcutDescription);
  5321.  
  5322. return button;
  5323. },
  5324.  
  5325. searchCanceled: function()
  5326. {
  5327. if (this._searchView)
  5328. this._searchView.searchCanceled();
  5329.  
  5330. delete this._searchView;
  5331. delete this._searchQuery;
  5332. },
  5333.  
  5334.  
  5335. performSearch: function(query)
  5336. {
  5337. WebInspector.searchController.updateSearchMatchesCount(0, this);
  5338.  
  5339. if (!this.visibleView)
  5340. return;
  5341.  
  5342.  
  5343. this.searchCanceled();
  5344.  
  5345. this._searchView = this.visibleView;
  5346. this._searchQuery = query;
  5347.  
  5348. function finishedCallback(view, searchMatches)
  5349. {
  5350. if (!searchMatches)
  5351. return;
  5352.  
  5353. WebInspector.searchController.updateSearchMatchesCount(searchMatches, this);
  5354. view.jumpToNextSearchResult();
  5355. WebInspector.searchController.updateCurrentMatchIndex(view.currentSearchResultIndex, this);
  5356. }
  5357.  
  5358. this._searchView.performSearch(query, finishedCallback.bind(this));
  5359. },
  5360.  
  5361. jumpToNextSearchResult: function()
  5362. {
  5363. if (!this._searchView)
  5364. return;
  5365.  
  5366. if (this._searchView !== this.visibleView) {
  5367. this.performSearch(this._searchQuery);
  5368. return;
  5369. }
  5370.  
  5371. if (this._searchView.showingLastSearchResult())
  5372. this._searchView.jumpToFirstSearchResult();
  5373. else
  5374. this._searchView.jumpToNextSearchResult();
  5375. WebInspector.searchController.updateCurrentMatchIndex(this._searchView.currentSearchResultIndex, this);
  5376. return true;
  5377. },
  5378.  
  5379. jumpToPreviousSearchResult: function()
  5380. {
  5381. if (!this._searchView)
  5382. return false;
  5383.  
  5384. if (this._searchView !== this.visibleView) {
  5385. this.performSearch(this._searchQuery);
  5386. if (this._searchView)
  5387. this._searchView.jumpToLastSearchResult();
  5388. return;
  5389. }
  5390.  
  5391. if (this._searchView.showingFirstSearchResult())
  5392. this._searchView.jumpToLastSearchResult();
  5393. else
  5394. this._searchView.jumpToPreviousSearchResult();
  5395. WebInspector.searchController.updateCurrentMatchIndex(this._searchView.currentSearchResultIndex, this);
  5396. },
  5397.  
  5398.  
  5399. canSearchAndReplace: function()
  5400. {
  5401. var view =   (this.visibleView);
  5402. return !!view && view.canEditSource();
  5403. },
  5404.  
  5405.  
  5406. replaceSelectionWith: function(text)
  5407. {
  5408. var view =   (this.visibleView);
  5409. view.replaceSearchMatchWith(text);
  5410. },
  5411.  
  5412.  
  5413. replaceAllWith: function(query, text)
  5414. {
  5415. var view =   (this.visibleView);
  5416. view.replaceAllWith(query, text);
  5417. },
  5418.  
  5419. _toggleFormatSource: function()
  5420. {
  5421. this._toggleFormatSourceButton.toggled = !this._toggleFormatSourceButton.toggled;
  5422. var uiSourceCodes = this._workspace.uiSourceCodes();
  5423. for (var i = 0; i < uiSourceCodes.length; ++i)
  5424. uiSourceCodes[i].setFormatted(this._toggleFormatSourceButton.toggled);
  5425. },
  5426.  
  5427. addToWatch: function(expression)
  5428. {
  5429. this.sidebarPanes.watchExpressions.addExpression(expression);
  5430. },
  5431.  
  5432. _toggleBreakpoint: function()
  5433. {
  5434. var sourceFrame = this.visibleView;
  5435. if (!sourceFrame)
  5436. return;
  5437.  
  5438. if (sourceFrame instanceof WebInspector.JavaScriptSourceFrame) {
  5439. var javaScriptSourceFrame =   (sourceFrame);
  5440. javaScriptSourceFrame.toggleBreakpointOnCurrentLine();
  5441. }            
  5442. },
  5443.  
  5444. _showOutlineDialog: function()
  5445. {
  5446. var uiSourceCode = this._editorContainer.currentFile();
  5447. if (!uiSourceCode)
  5448. return;
  5449.  
  5450. switch (uiSourceCode.contentType()) {
  5451. case WebInspector.resourceTypes.Document:
  5452. case WebInspector.resourceTypes.Script:
  5453. WebInspector.JavaScriptOutlineDialog.show(this.visibleView, uiSourceCode);
  5454. break;
  5455. case WebInspector.resourceTypes.Stylesheet:
  5456. WebInspector.StyleSheetOutlineDialog.show(this.visibleView, uiSourceCode);
  5457. break;
  5458. }
  5459. },
  5460.  
  5461. _installDebuggerSidebarController: function()
  5462. {
  5463. this._toggleDebuggerSidebarButton = new WebInspector.StatusBarButton(WebInspector.UIString("Hide debugger"), "scripts-debugger-show-hide-button", 3);
  5464. this._toggleDebuggerSidebarButton.state = "shown";
  5465. this._toggleDebuggerSidebarButton.addEventListener("click", clickHandler, this);
  5466.  
  5467. function clickHandler()
  5468. {
  5469. if (this._toggleDebuggerSidebarButton.state === "shown")
  5470. this._hideDebuggerSidebar();
  5471. else
  5472. this._showDebuggerSidebar();
  5473. }
  5474. this.editorView.element.appendChild(this._toggleDebuggerSidebarButton.element);
  5475.  
  5476. if (WebInspector.settings.debuggerSidebarHidden.get())
  5477. this._hideDebuggerSidebar();
  5478.  
  5479. },
  5480.  
  5481. _showDebuggerSidebar: function()
  5482. {
  5483. if (this._toggleDebuggerSidebarButton.state === "shown")
  5484. return;
  5485. this._toggleDebuggerSidebarButton.state = "shown";
  5486. this._toggleDebuggerSidebarButton.title = WebInspector.UIString("Hide debugger");
  5487. this.splitView.showSidebarElement();
  5488. this.debugSidebarResizeWidgetElement.removeStyleClass("hidden");
  5489. WebInspector.settings.debuggerSidebarHidden.set(false);
  5490. },
  5491.  
  5492. _hideDebuggerSidebar: function()
  5493. {
  5494. if (this._toggleDebuggerSidebarButton.state === "hidden")
  5495. return;
  5496. this._toggleDebuggerSidebarButton.state = "hidden";
  5497. this._toggleDebuggerSidebarButton.title = WebInspector.UIString("Show debugger");
  5498. this.splitView.hideSidebarElement();
  5499. this.debugSidebarResizeWidgetElement.addStyleClass("hidden");
  5500. WebInspector.settings.debuggerSidebarHidden.set(true);
  5501. },
  5502.  
  5503. _fileRenamed: function(event)
  5504. {
  5505. var uiSourceCode =   (event.data.uiSourceCode);
  5506. var name =   (event.data.name);
  5507. if (!uiSourceCode.isSnippet)
  5508. return;
  5509. WebInspector.scriptSnippetModel.renameScriptSnippet(uiSourceCode, name);
  5510. },
  5511.  
  5512.  
  5513. _snippetCreationRequested: function(event)
  5514. {
  5515. var uiSourceCode = WebInspector.scriptSnippetModel.createScriptSnippet();
  5516. this._showSourceLine(uiSourceCode);
  5517.  
  5518. var shouldHideNavigator = !this._navigatorController.isNavigatorPinned();
  5519. if (this._navigatorController.isNavigatorHidden())
  5520. this._navigatorController.showNavigatorOverlay();
  5521. this._navigator.rename(uiSourceCode, callback.bind(this));
  5522.  
  5523.  
  5524. function callback(committed)
  5525. {
  5526. if (shouldHideNavigator)
  5527. this._navigatorController.hideNavigatorOverlay();
  5528.  
  5529. if (!committed) {
  5530. WebInspector.scriptSnippetModel.deleteScriptSnippet(uiSourceCode);
  5531. return;
  5532. }
  5533.  
  5534. this._showSourceLine(uiSourceCode);
  5535. }
  5536. },
  5537.  
  5538.  
  5539. _itemRenamingRequested: function(event)
  5540. {
  5541. var uiSourceCode =   (event.data);
  5542.  
  5543. var shouldHideNavigator = !this._navigatorController.isNavigatorPinned();
  5544. if (this._navigatorController.isNavigatorHidden())
  5545. this._navigatorController.showNavigatorOverlay();
  5546. this._navigator.rename(uiSourceCode, callback.bind(this));
  5547.  
  5548.  
  5549. function callback(committed)
  5550. {
  5551. if (shouldHideNavigator && committed) {
  5552. this._navigatorController.hideNavigatorOverlay();
  5553. this._showSourceLine(uiSourceCode);
  5554. }
  5555. }
  5556. },
  5557.  
  5558.  
  5559. _showLocalHistory: function(uiSourceCode)
  5560. {
  5561. WebInspector.RevisionHistoryView.showHistory(uiSourceCode);
  5562. },
  5563.  
  5564.  
  5565. appendApplicableItems: function(event, contextMenu, target)
  5566. {
  5567. this._appendUISourceCodeItems(contextMenu, target);
  5568. this._appendFunctionItems(contextMenu, target);
  5569. },
  5570.  
  5571.  
  5572. _appendUISourceCodeItems: function(contextMenu, target)
  5573. {
  5574. if (!(target instanceof WebInspector.UISourceCode))
  5575. return;
  5576.  
  5577. var uiSourceCode =   (target);
  5578. contextMenu.appendItem(WebInspector.UIString("Local modifications..."), this._showLocalHistory.bind(this, uiSourceCode));
  5579. var resource = WebInspector.resourceForURL(uiSourceCode.url);
  5580. if (resource && resource.request)
  5581. contextMenu.appendApplicableItems(resource.request);
  5582. },
  5583.  
  5584.  
  5585. _appendFunctionItems: function(contextMenu, target)
  5586. {
  5587. if (!(target instanceof WebInspector.RemoteObject))
  5588. return;
  5589. var remoteObject =   (target);
  5590. if (remoteObject.type !== "function")
  5591. return;
  5592.  
  5593. function didGetDetails(error, response)
  5594. {
  5595. if (error) {
  5596. console.error(error);
  5597. return;
  5598. }
  5599. WebInspector.inspectorView.showPanelForAnchorNavigation(this);
  5600. var uiLocation = WebInspector.debuggerModel.rawLocationToUILocation(response.location);
  5601. this._showSourceLine(uiLocation.uiSourceCode, uiLocation.lineNumber);
  5602. }
  5603.  
  5604. function revealFunction()
  5605. {
  5606. DebuggerAgent.getFunctionDetails(remoteObject.objectId, didGetDetails.bind(this));
  5607. }
  5608.  
  5609. contextMenu.appendItem(WebInspector.UIString("Show function definition"), revealFunction.bind(this));
  5610. },
  5611.  
  5612. showGoToSourceDialog: function()
  5613. {
  5614. WebInspector.OpenResourceDialog.show(this, this._workspace, this.editorView.mainElement);
  5615. },
  5616.  
  5617. __proto__: WebInspector.Panel.prototype
  5618. }
  5619.